1 | It exists. |
0 | It does not exist. |
VarName | Name of variable to check for. |
LevelOffset | Optional. How many levels up to go. Default is 1 and will check the immediate caller.
|
This command uses uplevel
and info exists
to determine if the variable exists in the context of a caller.
For information regarding exceptions / errors, see
here.
The following code demonstrates VarExistsInCaller in three ways:
- Variable does exist in immediate caller.
- Variable does not exist in immediate caller.
- It does not exist in preceding caller (though it does exist in immediate caller).
proc Proc0 {} {
Proc1
}
proc Proc1 {} {
set abc 123
Proc2
}
proc Proc2 {} {
puts [VarExistsInCaller abc]
puts [VarExistsInCaller def]
puts [VarExistsInCaller abc 2]
}