debug.getstack

Reads register slots from a live Luau stack frame.

Syntax

Signature
debug.getstack(Level: number, Index: number?) -> any

Aliases

This function has no aliases.

Parameters

ParameterTypeDescription
LevelnumberPositive stack level selecting a live Luau frame.
Indexnumber?One-based slot to read. Omit to read all slots.

Returns

TypeDescription
anySelected slot value, or a table of slot values when Index is omitted.

Notes

Level 1 selects the calling frame. With Index omitted, returns the frame's slots in a one-based table. With Index supplied, returns just that slot. These slots are VM registers rather than a list of named local variables.

Example

Luau
local function Example()
    local Message = "Hello"
    print(debug.getstack(1))
    return Message
end
Example()