Cecil Westerhof <
Ce...@decebal.nl> wrote:
> In a way that is what I do. Only instead of putting the code in every
> function I wrote a function to get it. And because
> info level 0
> does not work when you are not in proc. I would expect:
> info level 1
> not to work when the proc is not called from a proc.
I suggest re-reading the doc for info level:
" info level ?number?
" If number is not specified, this command returns a number
" giving the stack level of the invoking procedure, or 0 if the
" command is invoked at top-level. If number is specified, then
" the result is a list consisting of the name and arguments for
" the procedure call at level number on the stack.
pay extra attention here:
" If number is
" positive then it selects a particular stack level (1 refers
" to the top-most active procedure, 2 to the procedure
" it called, and so on);
And that's what you probably need instead: (0 or negative levels)
" otherwise it gives a level relative
" to the current level (0 refers to the current procedure,
" -1 to its caller, and so on).
You probably want to query info level -1 from your proc.
" See the uplevel command for
" more information on what stack levels mean.
For some hands-on experimenting, I suggest:
proc top lvl {med $lvl}
proc med lvl {bot $lvl}
proc bot lvl {info level $lvl}
foreach lvl {-3 -2 -1 0 1 2 3 4} { catch { top $lvl } msg; puts "$lvl: $msg" }
Spoiler: the observed behaviour is entirely correct wrt the doc.