info(n) | Tcl Built-In Commands | info(n) |
info - Return information about the state of the Tcl interpreter
info option ?arg arg ...?
This command provides information about various internals of the Tcl interpreter. The legal options (which may be abbreviated) are:
If number is positive (> 0) then it selects a particular stack level (1 refers to the top-most active command, i.e., info frame itself, 2 to the command it was called from, and so on); otherwise it gives a level relative to the current command (0 refers to the current command, i.e., info frame itself, -1 to its caller, and so on).
This is similar to how info level works, except that this subcommand reports all frames, like sourced scripts, evals, uplevels, etc.
Note that for nested commands, like “foo [bar [x]]”, only “x” will be seen by an info frame invoked within “x”. This is the same as for info level and error stack traces.
The result dictionary may contain the keys listed below, with the specified meanings for their values:
A thing of note is that for procedures statically defined in files the locations of commands in their bodies will be reported with type source and absolute line numbers, and not as type proc. The same is true for procedures nested in statically defined procedures, and literal eval scripts in files or statically defined procedures.
In contrast, a procedure definition or eval within a dynamically evaluated environment count linenumbers relative to the start of their script, even if they would be able to count relative to the start of the outer dynamic script. That type of number usually makes more sense.
A different way of describing this behaviour is that file based locations are tracked as deeply as possible, and where this is not possible the lines are counted based on the smallest possible eval or procedure body, as that scope is usually easier to find than any dynamic outer scope.
The syntactic form {*} is handled like eval. I.e. if it is given a literal list argument the system tracks the linenumber within the list words as well, and otherwise all linenumbers are counted relative to the start of each word (smallest scope)
This command prints out a procedure suitable for saving in a Tcl script:
proc printProc {procName} { set result [list proc $procName] set formals {} foreach var [info args $procName] { if {[info default $procName $var def]} { lappend formals [list $var $def] } else { # Still need the list-quoting because variable # names may properly contain spaces. lappend formals [list $var] } } puts [lappend result $formals [info body $procName]] }
global(n), proc(n)
command, information, interpreter, level, namespace, procedure, variable
8.4 | Tcl |