Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TCL Proc names

5 views
Skip to first unread message

georg...@yahoo.com

unread,
Jan 14, 2007, 4:14:47 PM1/14/07
to
I need a way to find the current Proc name and also the previous Proc
names. I need this to print out debug information. Here is an
example:

proc f1 {} {
f2
}

proc f2 {} {
puts "The last 2 procs called is: ??????"
}

# main
f1

--------------------------
# Desired output

The last 2 procs called is: f2(), f1(), main()

Thanks,

Bryan Oakley

unread,
Jan 14, 2007, 5:09:17 PM1/14/07
to
georg...@yahoo.com wrote:
> I need a way to find the current Proc name and also the previous Proc
> names. I need this to print out debug information. Here is an
> example:

read the man pages on the "info" command. Specifically, [info level].
You can use that command to work your way up through the call stack.

Manfred Stelzhammer

unread,
Jan 14, 2007, 5:14:28 PM1/14/07
to
proc main {} {
f1

}
proc f1 {} {
f2
}
proc f2 {} {
puts "the last 2 proc called are [info level 0] [info level 2] [info
level 1]"
}
main

Regards
Manfred

Michael A. Cleverly

unread,
Jan 14, 2007, 5:22:24 PM1/14/07
to
On Sun, 14 Jan 2007, georg...@yahoo.com wrote:

> I need a way to find the current Proc name and also the previous Proc
> names. I need this to print out debug information.

The command you'll want to use is [info level]. See:
http://wiki.tcl.tk/1720

Try something like:

proc callstack {{level -1}} {
if {![string is integer -strict $level]} then {
return -code error "expected integer but got \"$level\""
}

if {$level > 0} then {
return -code error "expected integer <= 0 but got \"$level\""
}

set tcl_call_stack ""
set level [expr {[info level] + $level + 1}]

while {[incr level -1] > 0} {
append tcl_call_stack " called from [info level $level]" \n
}

return [string trimright $tcl_call_stack]
}

Michael

Darren New

unread,
Jan 14, 2007, 8:43:56 PM1/14/07
to
georg...@yahoo.com wrote:
> I need a way to find the current Proc name and also the previous Proc
> names.

You seek the [info] command, and in particular the [info level] subcommand.

--
Darren New / San Diego, CA, USA (PST)
Scruffitarianism - Where T-shirt, jeans,
and a three-day beard are "Sunday Best."

0 new messages