I wrote a Lua script that uses the debug API ( debug.sethook ) to intercept calls and returns. I use it to print a beautifully formatted call tree, which is very useful for debugging.
In the hook handler function, I increment or decrement the indentLevel global variable indentLevel on whether the event is a “call” or “return” (or “tail return”). Then I use debug.getinfo to get information about the calling function and upload it to stdout at the current indent level.
For call events, I would also like to print the values of the parameters that were passed to a particular call. Presumably, I could do this in the implementation of the C / C ++ hook handler function by looking at the Lua stack.
Does anyone know if there is a way to determine parameter values from a debug handler function in Lua?
source share