diff options
author | dkf <dkf@noemail.net> | 2011-08-01 09:34:08 (GMT) |
---|---|---|
committer | dkf <dkf@noemail.net> | 2011-08-01 09:34:08 (GMT) |
commit | 8c7c2862b5ebef2f72a50e4434bac0e93f4d169a (patch) | |
tree | 9febb6eb757a3ecc9740439500718156e6969e56 | |
parent | d139c6beafe0d8598ece7b9e9325e7ff8a96ea0f (diff) | |
download | tcl-8c7c2862b5ebef2f72a50e4434bac0e93f4d169a.zip tcl-8c7c2862b5ebef2f72a50e4434bac0e93f4d169a.tar.gz tcl-8c7c2862b5ebef2f72a50e4434bac0e93f4d169a.tar.bz2 |
Added some examples of how some of the standard global variables can be used,
following prompting by a request by Robert Hicks.
FossilOrigin-Name: 02393482fbdc7765293b1b088aad1fc5b1ee98a4
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | doc/tclvars.n | 37 |
2 files changed, 41 insertions, 0 deletions
@@ -1,5 +1,9 @@ 2011-08-01 Donal K. Fellows <dkf@users.sf.net> + * doc/tclvars.n (EXAMPLES): Added some examples of how some of the + standard global variables can be used, following prompting by a + request by Robert Hicks. + * tools/tcltk-man2html.tcl (plus-pkgs): [Bug 3382474]: Added code to determine the version number of contributed packages from their directory names so that HTML documentation builds are less confusing. 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 |