Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you can use debug.sethook() to set up a hook that gets called each time certain special events happen in lua. it can be useful for things like this.</p> <pre><code>local debugInfo = { caller = nil, callee = nil } function hook() local info = debug.getinfo(2) if info == nil then debugInfo.callee = nil return end -- we only want to watch lua function calls (not C functions) if info.what ~= "Lua" then debugInfo.callee = "C function" return end debugInfo.caller = debugInfo.callee debugInfo.callee = info.name end debug.sethook(hook, "c") function caller1() if debugInfo.caller ~= nil and debugInfo.callee ~= nil then msg = debugInfo.callee.. " was called by ".. debugInfo.caller.. "!" print(msg) end end function caller2() caller1() end caller2() </code></pre> <p>this prints 'caller1 was called from caller2!'</p> <p>debug.sethook can handle 3 different characters in the second parameter so you can let it know when to notify you. 'c' means call your hook function any time a function is called in lua, 'r' means call your hook function every time a function returns in lua, and 'l' means call your hook function whenever lua processes a new line of code. </p> <p>you could set this up to build your own custom stack trace if you really wanted to, and you could also use debug.getlocal() within your hook to even try to work out what arguments were passed to your called function.</p> <p>edit for lhf. this is actually a much simpler way of doing what you're asking, if you don't need to track this and just need to know the context of how the function was called.</p> <pre><code>function caller1() local current_func = debug.getinfo(1) local calling_func = debug.getinfo(2) print(current_func.name.. " was called by ".. calling_func.name.. "!") end function caller2() caller1() end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload