0Pricing
Lua Academy · Lesson

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

  1. math Library Functions
  2. table Library Functions
  3. os and io Libraries
  4. The debug Library
← Back to Lua Academy