Volt

debug.getstack

Gets a value from the stack at a specific level and index.

Syntax

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

Parameters

ParameterTypeDescription
levelnumberThe stack level (1 = current function)
indexnumberThe stack slot index

Returns

TypeDescription
anyThe value at the specified stack position

Description

debug.getstack retrieves a value from the call stack. This allows you to read local variables and temporary values from any level of the current call stack.

Example

local function level2()
    local secret = "hidden value"
    level1()
end

local function level1()
    -- Get the 'secret' variable from level2
    local value = debug.getstack(2, 1)
    print(value) -- "hidden value"
end

level2()

Stack Levels

LevelMeaning
1Current function
2Calling function
3Caller of the caller
...And so on

Notes

  • Stack indices correspond to local variable slots
  • The exact index depends on the function's compiled bytecode
  • Values may include locals, parameters, and temporaries

On this page