Gnocl Cookbook‎ > ‎

Caller Level




#---------------
# Return the call stack to the execution of the script.
#---------------
# NB: Does not work with TclOO
# http://wiki.tcl.tk/16183
#---------------
# Arguments:
#    none
# Returns:
#    none
proc call_stack {} {
       set distanceToTop [info level]
       for {set i 2} {$i < $distanceToTop} {incr i} {
          set callerlevel [expr {$distanceToTop - $i}]
          puts "CALLER $callerlevel: [info level $callerlevel]"
      }
}



proc x {a} {
    puts "Entered x, args $a"
    call_stack
    }
   
proc a { args } {   
    x abc  
    }

proc b { args } {
    a she sells sea shells by the sea shore
    }

b how now brown cow


Running this will print the following to the console:


b how now brown cow
Entered x, args abc
CALLER 2: a she sells sea shells by the sea shore
CALLER 1: b how now brown cow



Comments