debug.setstack
Sets a value on the stack at a specific level and index.
Syntax
debug.setstack(level: number, index: number, value: any) -> ()
debug.setstack(thread: thread, level: number, index: number, value: any) -> ()Parameters
| Parameter | Type | Description |
|---|---|---|
level | number | The stack level (1 = current function) |
index | number | The stack slot index |
value | any | The new value to set |
thread | thread? | Optional thread to modify before level |
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()
for index, stackValue in ipairs(debug.getstack(2)) do
if stackValue == "original" then
debug.setstack(2, index, "modified!")
return
end
end
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