static.tcl

来自「TKCVS Source Code For CVS。」· TCL 代码 · 共 40 行

TCL
40
字号
#
#  DESCRIPTION
#      This file contains a procedure written in Tcl that supports static
#      variables.
#
#+ static - static variables support
#
#    This procedure supports static variables for a procedure whole through
#    Tcl code.  This procedure is based on code from the authors of the
#    tclX extension.
#
# REQUIREMENTS
#    None.
#
# RETURNS
#    Nothing.
#
# EXAMPLE
#    static {foo 10} bar
#
# CAVEATES
#    None.
#
proc static {args} {
    global staticvars
    set procName [lindex [info level -1] 0]
    foreach varPair $args {
	set varName [lindex $varPair 0]
	if {[llength $varPair] != 1} {
	    set varValue [lrange $varPair 1 end]
	} else {
	    set varValue {}
	}
	if {! [info exists staticvars($procName:$varName)]} {
	    set staticvars($procName:$varName) $varValue
	}
	uplevel 1 "upvar #0 staticvars($procName:$varName) $varName"
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?