debug.setstack

Writes a register slot in a live Luau stack frame.

Syntax

Signature
debug.setstack(Level: number, Index: number, Value: any) -> ()

Aliases

This function has no aliases.

Parameters

ParameterTypeDescription
LevelnumberPositive stack level selecting a live Luau frame.
IndexnumberOne-based frame slot.
ValueanyValue written to the slot.

Returns

TypeDescription
()None.

Notes

Level 1 selects the calling frame and Index starts at 1. Invalid frames and slot indexes raise errors.

Example

Luau
local function Example()
    local Message = "Before"
    local Values = debug.getstack(1)
    for Index, Value in Values do
        if Value == "Before" then debug.setstack(1, Index, "After") break end
    end
    return Message
end
print(Example())