📄 uplevel.n
字号:
'\"'\" Copyright (c) 1993 The Regents of the University of California.'\" Copyright (c) 1994-1997 Sun Microsystems, Inc.'\"'\" See the file "license.terms" for information on usage and redistribution'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.'\" '\" SCCS: @(#) uplevel.n 1.8 97/08/13 13:41:36'\" .so man.macros.TH uplevel n "" Tcl "Tcl Built-In Commands".BS'\" Note: do not modify the .SH NAME line immediately below!.SH NAMEuplevel \- Execute a script in a different stack frame.SH SYNOPSIS\fBuplevel \fR?\fIlevel\fR?\fI arg \fR?\fIarg ...\fR?.BE.SH DESCRIPTION.PPAll of the \fIarg\fR arguments are concatenated as if they hadbeen passed to \fBconcat\fR; the result is then evaluated in thevariable context indicated by \fIlevel\fR. \fBUplevel\fR returnsthe result of that evaluation..PPIf \fIlevel\fR is an integer thenit gives a distance (up the procedure calling stack) to move beforeexecuting the command. If \fIlevel\fR consists of \fB#\fR followed bya number then the number gives an absolute level number. If \fIlevel\fRis omitted then it defaults to \fB1\fR. \fILevel\fR cannot bedefaulted if the first \fIcommand\fR argument starts with a digit or \fB#\fR..PPFor example, suppose that procedure \fBa\fR was invokedfrom top-level, and that it called \fBb\fR, and that \fBb\fR called \fBc\fR.Suppose that \fBc\fR invokes the \fBuplevel\fR command. If \fIlevel\fRis \fB1\fR or \fB#2\fR or omitted, then the command will be executedin the variable context of \fBb\fR. If \fIlevel\fR is \fB2\fR or \fB#1\fRthen the command will be executed in the variable context of \fBa\fR.If \fIlevel\fR is \fB3\fR or \fB#0\fR then the command will be executedat top-level (only global variables will be visible)..PPThe \fBuplevel\fR command causes the invoking procedure to disappearfrom the procedure calling stack while the command is being executed.In the above example, suppose \fBc\fR invokes the command.CS\fBuplevel 1 {set x 43; d}\fR.CEwhere \fBd\fR is another Tcl procedure. The \fBset\fR command willmodify the variable \fBx\fR in \fBb\fR's context, and \fBd\fR will executeat level 3, as if called from \fBb\fR. If it in turn executesthe command.CS\fBuplevel {set x 42}\fR.CEthen the \fBset\fR command will modify the same variable \fBx\fR in \fBb\fR'scontext: the procedure \fBc\fR does not appear to be on the call stackwhen \fBd\fR is executing. The command ``\fBinfo level\fR'' maybe used to obtain the level of the current procedure..PP\fBUplevel\fR makes it possible to implement new controlconstructs as Tcl procedures (for example, \fBuplevel\fR couldbe used to implement the \fBwhile\fR construct as a Tcl procedure)..PP\fBnamespace eval\fR is another way (besides procedure calls)that the Tcl naming context can change.It adds a call frame to the stack to represent the namespace context.This means each \fBnamespace eval\fR commandcounts as another call level for \fBuplevel\fR and \fBupvar\fR commands.For example, \fBinfo level 1\fR will return a listdescribing a command that is eitherthe outermost procedure call or the outermost \fBnamespace eval\fR command.Also, \fBuplevel #0\fR evaluates a scriptat top-level in the outermost namespace (the global namespace)..SH "SEE ALSO"namespace(n).SH KEYWORDScontext, level, namespace, stack frame, variables
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -