Version 1 of GetProcName/GetScriptName

Updated 2018-01-09 19:21:27 by kpv

Created by CecilWesterhof.

I often want to know the name of the proc, or the name of the script. For this I wrote the following procs:

proc getProcName {} {
    set currentProc [info level 0]
    set callingProc [info level 1]
    # When not called from a proc, callingProc is the same as currentProc
    if {${currentProc} eq ${callingProc}} {
        error [format "ERROR: %s not called from a proc" ${currentProc}]
    }
    return [lindex ${callingProc} 0]
}

proc getScriptName {} {
    file tail ${::argv0}
}

As always: comments, tips and questions are appreciated.

KPV Also checkout out List the call stack.