Syntax
setstack(level: number, index: number, value: any)Aliases
debug.setstackArguments
| Name | Type | Description |
|---|---|---|
level | number | Stack level number. Must satisfy 0 <= level < the current call stack depth. |
index | number | One-based stack slot index. |
value | any | New value for the stack slot. |
Description
Replaces one stack slot value in a Lua stack frame. level and index are required numbers. level must satisfy 0 <= level < the current call stack depth; invalid levels raise "Level out of range". C closure frames raise "Lua function expected". index is one-based and must refer to an existing stack slot; invalid indexes raise "Stack index out of range". debug.setstack is an alias.
Call it with 3 parameter(s): level, index, value. The argument table explains which values are required and which ones only refine the behavior.
It does not return data. Treat the call as an action and handle errors around the call site when needed.
Example
Replace one stack slot value in a Lua stack frame.
local function inspect(value)
print(getstack(1, 1))
setstack(1, 1, "updated")
print(getstack(1, 1))
debug.setstack(1, 1, value)
end
inspect("ready")