summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2011-08-01 09:34:08 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2011-08-01 09:34:08 (GMT)
commita51e3eead5f69832eaa7002d41e40b3b6ae4f646 (patch)
tree9febb6eb757a3ecc9740439500718156e6969e56 /doc
parent84631930502efd5f508061e9c4ae81d8413f3ecf (diff)
downloadtcl-a51e3eead5f69832eaa7002d41e40b3b6ae4f646.zip
tcl-a51e3eead5f69832eaa7002d41e40b3b6ae4f646.tar.gz
tcl-a51e3eead5f69832eaa7002d41e40b3b6ae4f646.tar.bz2
Added some examples of how some of the standard global variables can be used,
following prompting by a request by Robert Hicks.
Diffstat (limited to 'doc')
-rw-r--r--doc/tclvars.n37
1 files changed, 37 insertions, 0 deletions
diff --git a/doc/tclvars.n b/doc/tclvars.n
index b126b7f..3bd18e8 100644
--- a/doc/tclvars.n
+++ b/doc/tclvars.n
@@ -485,6 +485,7 @@ bug fixes that retain backward compatibility.
The value of this variable is returned by the \fBinfo tclversion\fR
command.
.SH "OTHER GLOBAL VARIABLES"
+.PP
The following variables are only guaranteed to exist in \fBtclsh\fR
and \fBwish\fR executables; the Tcl library does not define them
itself but many Tcl environments do.
@@ -508,6 +509,42 @@ was invoked.
Contains 1 if \fBtclsh\fR or \fBwish\fR is running interactively (no
script was specified and standard input is a terminal-like device), 0
otherwise.
+.SH EXAMPLES
+.PP
+To add a directory to the collection of locations searched by
+\fBpackage require\fR, e.g., because of some application-specific
+packages that are used, the \fBauto_path\fR variable needs to be
+updated:
+.PP
+.CS
+lappend ::\fBauto_path\fR [file join [pwd] "theLibDir"]
+.CE
+.PP
+A simple though not very robust way to handle command line arguments
+of the form
+.QW "\-foo 1 \-bar 2"
+is to load them into an array having first loaded in the default settings:
+.CS
+array set arguments {-foo 0 -bar 0 -grill 0}
+array set arguments $::\fBargv\fR
+puts "foo is $arguments(-foo)"
+puts "bar is $arguments(-bar)"
+puts "grill is $arguments(-grill)"
+.CE
+.PP
+The \fBargv0\fR global variable can be used (in conjunction with the
+\fBinfo script\fR command) to determine whether the current script is
+being executed as the main script or loaded as a library. This is
+useful because it allows a single script to be used as both a library
+and a demonstration of that library:
+.PP
+.CS
+if {$::\fBargv0\fR eq [info script]} {
+ # running as: tclsh example.tcl
+} else {
+ package provide Example 1.0
+}
+.CE
.SH "SEE ALSO"
eval(n), library(n), tclsh(1), tkvars(n), wish(1)
.SH KEYWORDS