summaryrefslogtreecommitdiffstats
path: root/doc/namespace.n
diff options
context:
space:
mode:
Diffstat (limited to 'doc/namespace.n')
-rw-r--r--doc/namespace.n28
1 files changed, 26 insertions, 2 deletions
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)