info frame
Gives the count of the levels of the running code, or a dict that describes one level.
info frame ?LEVEL?
Description
A level of the running code is the run of a file, of a proc body, or of a script that a command runs, such as the script of eval or uplevel. These levels are not the levels of info level. As in Tcl, a script that if, while, for, switch, or try runs is a part of the level of its command.
With no LEVEL, gives the count of the levels. With LEVEL, gives a dict that describes that level. A LEVEL above 0 counts from the outermost level: 1 is the first. A LEVEL of 0 or less counts back from the running level: 0 is the level of the call of info frame, and -1 is the level of the command that started it. A LEVEL past either end is an error.
The dict has these keys:
type:sourcefor code of a file,procfor the body of a proc that is not a literal word of a file, andevalfor a script that a command runs from a value, such aseval $s. With no level, as in a command that the host calls,info frame 0andinfo frame 1give only the typeprecompiled.line: the line of the command, from 1: in its file for the typesource, and in its script for the typesprocandeval.file: the path of the file, for the typesource.cmd: the text of the command that runs at that level. At level 0 it is the call ofinfo frame.proc: the full name of the proc, when the level is in the body of a proc.lambda: the lambda ofapply, when the level is in the body of a lambda.method, withclassorobject: the method and its class or object, when the level is in the body of a method of TclOO.level: how many levels ofinfo levelthe level is above the running proc: 0 for the running proc and 1 for its caller. A level that is not in the chain of calls of the running proc, such as the level of a call ofuplevel, has nolevel.
The body of a proc has the type source and the lines of its file when the body is a literal word of the file. Each other proc body has the type proc, with lines from 1 in the body.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| LEVEL | integer | none | The level: from the outermost level above 0, from the running level at 0 or less. |
Returns
The count of the levels, or a dict of one level.
Examples
% proc f {} {dict get [info frame 0] proc}; f
::f
% proc f {} {dict get [info frame 0] type}; f
proc
% proc f {} {dict get [info frame 0] cmd}; f
info frame 0
% proc f {} {dict get [info frame -1] cmd}; proc g {} {f}; g
f
% proc f {} {dict get [info frame -1] level}; proc g {} {f}; g
1
% proc f {x} {dict get [info frame 0] line}; f 1
1
% set s {dict get [info frame 0] type}; eval $s
eval
% apply {{} {dict get [info frame 0] lambda}}
{} {dict get [info frame 0] lambda}
% oo::class create C {method m {} {info frame 0}}
> dict get [[C new] m] method
m
Errors
% info frame 99
bad level "99"
-errorcode TCL LOOKUP LEVEL 99
% info frame -99
bad level "-99"
-errorcode TCL LOOKUP LEVEL -99
% info frame a
expected integer but got "a"
-errorcode TCL VALUE NUMBER
% info frame 1 2
wrong # args: should be "info frame ?number?"
-errorcode TCL WRONGARGS
Differences from Tcl
- A backslash-newline in a braced word makes the lines after it in that word one line lower than in Tcl. This is true of a proc body and of a script of
ifor another command. - A script that runs a second time is bytecode, and then the commands of it that ztcl compiles into its code add no level, also where Tcl adds one, such as
foreachoutside a proc. - In some cases of
{*}, the type and the line differ from Tcl. For example,eval {*}{info frame 0}in a file gives the typesourcewith the line of the file, where Tcl gives the typeevalwith line 1. substof a braced word in a file gives the typesourcewith the line of the file, where Tcl gives the typeevalwith line 1.- The body of a method of TclOO has the type
procwith lines from 1 in the body, where Tcl gives the typesourcewith the lines of the file. interp debugand its option-frameare not in ztcl.
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.5