Volt

debug.setstack

Sets a value on the stack at a specific level and index.

Syntax

debug.setstack(level: number, index: number, value: any) -> void

Parameters

ParameterTypeDescription
levelnumberThe stack level (1 = current function)
indexnumberThe stack slot index
valueanyThe new value to set

Returns

This function does not return a value.

Description

debug.setstack modifies a value on the call stack. This can change local variables in any active function on the stack.

Example

local function modifier()
    debug.setstack(2, 1, "modified!")
end

local function example()
    local value = "original"
    modifier()
    print(value) -- "modified!"
end

example()

Caution

Modifying stack values can cause crashes or undefined behavior if:

  • You set an incompatible type
  • The index doesn't exist
  • The value is used in unexpected ways

On this page