debug.getstack Gets one value or all values from a Luau stack frame.
debug . getstack ( level : number , index ? : number ) -> any | { any }
debug . getstack ( thread : thread , level : number , index ? : number ) -> any | { any }
Parameter Type Description levelnumberThe stack level (1 = current function) indexnumber?The stack slot index. Omit it to return every value at the level threadthread?Optional thread to inspect before level
Type Description any or {any}The selected value, or an array of every value when index is omitted
debug.getstack retrieves values from a Luau call frame. It throws if level refers to a C closure, including level 0.
local marker = "caller value"
local function inspectCaller ()
local callerStack = debug . getstack ( 2 )
for index , value in ipairs ( callerStack ) do
print ( index , value )
assert ( debug . getstack ( 2 , index ) == value )
end
end
inspectCaller ()
Level Meaning 1 Current function 2 Calling function 3 Caller of the caller ... And so on
Stack indices correspond to local variable slots
The exact index depends on the function's compiled bytecode
Values can include locals, parameters, functions, and temporary stack slots
Stack layout is compiler-dependent; do not assume an index without inspecting the frame