Posted to tcl by kostix at Sat Jun 07 13:51:59 GMT 2008view raw
- # Returns a fully-qualified name of the command that has invoked
- # the caller of this procedure.
- # To put is simple: if ::one::bar has invoked ::two::foo, the
- # ::two::foo proc can use [caller] to know that its caller
- # is ::one::bar
- # If the caller of this proc has no caller (i.e. it was called
- # on level 0), this proc returns empty string.
- # You can specify 2, 3, etc as the argument to get info about
- # the caller of the caller and so on (think of [uplevel]).
- proc caller {{level 1}} {
- incr level
- if {[catch {info level -$level} prc]} {
- return ""
- } else {
- return [namespace which -command [lindex $prc 0]]
- }
- }