ReferenceDebug

debug.getstack

Reads a live Lua frame’s stack slots.

Syntax

debug.getstack(level: number, index: number?) -> any

Also available as

getstackget_stack

Parameters

ParameterTypeDescription
levelnumberVisible caller level, starting at 1.
indexnumber?One-based slot; omit to inspect all slots.

Returns

TypeDescription
anySelected slot value, or a table when index is omitted.

Description

Level 1 identifies the Lua caller; larger levels walk outward through visible frames. Slots are temporary VM values, not stable source-variable names. C frames and invalid indices raise errors. Omitting index returns a table of the frame’s slots. A thread can be supplied before level to inspect a supported suspended thread.

Example

local function inspect()
    local marker = "stack-example"
    local slots = debug.getstack(1)
    print(marker, type(slots))
end
inspect()

These are Game executor contracts. Check build requirements and session lifetimes before using them.