Difference between revisions of "Name of the calling function (ISIS/Slang)"
Jump to navigation
Jump to search
(Created page with "Category:Isis / Slang In SLang a so-called ''frame'' specifies the execution of a closed piece of code, e.g., a function. All frames are pushed on to a frame stack and re...") |
|||
Line 1: | Line 1: | ||
[[Category:Isis / Slang]] | [[Category:Isis / Slang]] | ||
− | In SLang a so-called ''frame'' specifies the execution of a closed piece of code, e.g., a function. All frames are pushed | + | In SLang a so-called ''frame'' specifies the execution of a closed piece of code, e.g., a function. All frames are pushed onto a frame stack and removed once the execution of a particular frame finishes. By accessing this frame stack it is possible to trace back, e.g., a function call. |
There are a few functions in Slang available, which allows to receive information about frames (and even variables inside a particular frame!): | There are a few functions in Slang available, which allows to receive information about frames (and even variables inside a particular frame!): | ||
Line 15: | Line 15: | ||
variable call = _get_frame_info(_get_frame_depth()-1); | variable call = _get_frame_info(_get_frame_depth()-1); | ||
if (call.function == NULL) { message("I was called from the command line"); } | if (call.function == NULL) { message("I was called from the command line"); } | ||
− | else { vmessage("I was called by '%s'", | + | else { vmessage("I was called by '%s'", call.function); } |
} | } | ||
Latest revision as of 12:22, 2 May 2018
In SLang a so-called frame specifies the execution of a closed piece of code, e.g., a function. All frames are pushed onto a frame stack and removed once the execution of a particular frame finishes. By accessing this frame stack it is possible to trace back, e.g., a function call.
There are a few functions in Slang available, which allows to receive information about frames (and even variables inside a particular frame!):
- _get_frame_depth
- _get_frame_info
- _get_frame_variable
- _set_frame_variable
- _use_frame_namespace
We can use this to get the name of the parent function, which executes a child function:
define child() { variable call = _get_frame_info(_get_frame_depth()-1); if (call.function == NULL) { message("I was called from the command line"); } else { vmessage("I was called by '%s'", call.function); } } define parent() { child(); }
This will result in
isis> child(); I was called from the command line isis> parent(); I was called by 'parent'