I have written a Lua script that uses the debug API (debug.sethook
) to hook calls and returns. I use it to print out a nicely formatted call tree - which is very useful for debugging.
In the hook handler function I increment or decrement a global indentLevel
variable based on whether the event is 'call' or 'return' (or 'tail return'). I then use debug.getinfo
to get info about the calling function and dump it to stdout at the current indent level.
For 'call' events I would like to also print out the parameter values that were passed to the particular call. Presumably I could do this in a C/C++ implementation of the hook handler function by looking at the Lua stack.
Does anyone know if there is a way to determine the parameter values from within the debug handler function in Lua?