The debug library
Lua's debug library is not a debugger. Rather, it is all the building blocks needed to implement a debugger. One thing to remember when writing code against the debug library is it's going to be slow. On top of running your existing code, some extra work has to be done to enable debugging. All code related to the debug library is found in the debug
table (module).
The debug library provides hooks and introspective functions. Hooks let you hook into the runtime to trace what's happening with the program. Introspective functions, on the other hand, let you inspect various aspects of the running code. These aspects involve local variables, the scope of chunks, and so on.
Introspective information
Lua provides the debug.getinfo
function to inspect the currently running code. This function takes one of two arguments, either a function or an integer. When the argument is an integer, getinfo
will look the specified number of steps up the callstack. For example, let's assume you have...