debug.getstack
Reads values from a live Lua stack frame.
Supports both getstack(level, index?) and getstack(thread, level, index?). Slots are VM registers rather than named local variables. Nil slots are omitted from a table result.
debug.getstack(thread: thread?, level: number, index: number?): anyParameters
| Parameter | Type | Description |
|---|---|---|
thread | thread? | Optional leading target thread; omitted for the current thread. |
level | number | Reachable Lua frame level. |
index | number? | Optional one-based slot; omit for a table of slots. |
Example
local function sample()
local slots = debug.getstack(1)
for index, value in pairs(slots) do print(index, value) end
end
sample()Example output
1 table: 0x…The actual rows depend on the live registers of sample; expect one row per occupied slot with its index and current value.
Errors: Unreachable levels, C frames and out-of-range slots are rejected.
Aliases: getstack.
