diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | doc/namespace.n | 28 |
2 files changed, 30 insertions, 2 deletions
@@ -1,3 +1,7 @@ +2003-04-15 Joe English <jenglish@users.sourceforge.net> + * doc/namespace.n: added example section "SCOPED SCRIPTS", + supplied by Kevin Kenny. (Fixes [Bug 219183]) + 2003-04-15 Kevin Kenny <kennykb@acm.org> * makefile.vc: Updated makefile.vc to conform with Mo DeJong's diff --git a/doc/namespace.n b/doc/namespace.n index c79ce08..932cdaa 100644 --- a/doc/namespace.n +++ b/doc/namespace.n @@ -6,7 +6,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: namespace.n,v 1.9 2003/01/21 20:06:11 jenglish Exp $ +'\" RCS: @(#) $Id: namespace.n,v 1.10 2003/04/15 19:50:37 jenglish Exp $ '\" .so man.macros .TH namespace n 8.0 Tcl "Tcl Built-In Commands" @@ -66,7 +66,7 @@ extensions like Tk normally execute callback scripts in the global namespace. A scoped command captures a command together with its namespace context in a way that allows it to be executed properly later. -See the section \fBSCOPED VALUES\fR for some examples +See the section \fBSCOPED SCRIPTS\fR for some examples of how this is used to create callback scripts. .TP \fBnamespace current\fR @@ -568,6 +568,30 @@ may be imported by other namespaces. If a \fBnamespace import\fR command specifies a command that is not exported, the command is not imported. +.SH "SCOPED SCRIPTS" +The \fBnamespace code\fP command is the means by which a script may be +packaged for evaluation in a namespace other than the one in which it +was created. It is used most often to create event handlers, Tk bindings, +and traces for evaluation in the global context. For instance, the following +code indicates how to direct a variable trace callback into the current +namespace: +.CS +namespace eval a { + variable b + proc theTraceCallback { n1 n2 op } { + upvar 1 $n1 var + puts "the value of $n1 has changed to $var" + return + } + trace variable b w [namespace code theTraceCallback] +} +set a::b c +.CE +When executed, it prints the message: +.CS +the value of a::b has changed to c +.CE + .SH "SEE ALSO" variable(n) |