Printing parameters in Lua traceback
When an error occurs, Lua will print a traceback of the call stack, it helps us to find bugs. In many cases, however, a call stack traceback is not enough for us to find out the problem. We need more information, such as the environment, parameters of each function call, even all local variables of the stack.
I decide to modify Lua to improve traceback printing. Printing parameters of each function call does not yield too much output and can help us find bugs much better.
Just modify luaL_traceback
. lua_Debug.nparams
holds the number of parameters of the function, lua_getlocal
returns the local variable of the given function and index. Not difficult to do this.
1 |
|
Now, when an error occurs, we get the following output:
1 |
|
Printing parameters in Lua traceback
https://luyuhuang.tech/2020/12/01/lua-traceback-with-parameters.html