0Pricing
Lua Academy · Lesson

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

  1. The debug Library in Depth
  2. Remote Debugging with MobDebug
  3. Profiling with LuaProfiler
  4. Code Coverage and Test Instrumentation
← Back to Lua Academy