The debug Library
Inspect stack traces, locals, and upvalues with the debug library.
What Is the debug Library?
The debug library gives low-level access to Lua internals: stack frames, locals, upvalues, hooks, and coroutine state. Use it for debugging, not production logic.
debug.traceback
debug.traceback(msg, level) returns a string with the call stack. Commonly passed to xpcall as the error handler.
local ok, err = xpcall(function()
error("something went wrong")
end, debug.traceback)
print(err)All lessons in this course
- math Library Functions
- table Library Functions
- os and io Libraries
- The debug Library