debug.setstack
Sets a value on the stack at a specific level and index.
Syntax
debug.setstack(level: number, index: number, value: any) -> voidParameters
| Parameter | Type | Description |
|---|---|---|
level | number | The stack level (1 = current function) |
index | number | The stack slot index |
value | any | The 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
Related Functions
debug.getstack- Get a stack value