The debug Library in Depth
Use debug.traceback, getinfo, getlocal, getupvalue for introspection.
debug Library Overview
The debug library is Lua's introspection toolkit. It lets you inspect and modify the runtime state of any function, coroutine, or stack frame.
debug.getinfo Deep Dive
debug.getinfo(f, what) accepts what-flags: "n" (name), "S" (source), "l" (current line), "u" (upvalues), "f" (function ref).
local function foo()
local info = debug.getinfo(1, "nSlu")
print(info.name) -- foo
print(info.short_src) -- source file
print(info.currentline) -- line number
print(info.nups) -- number of upvalues
end
foo()All lessons in this course
- The debug Library in Depth
- Remote Debugging with MobDebug
- Profiling with LuaProfiler
- Code Coverage and Test Instrumentation