Syntax
setconstant(target: function | number, index: number, value: any)Aliases
debug.setconstantArguments
| Name | Type | Description |
|---|---|---|
target | function | number | Lua function or stack level whose constant is modified. |
index | number | One-based constant index. |
value | any | New value for the constant. |
Description
Replaces one constant in a Lua function or stack level by one-based index. Invalid stack levels raise "Level out of range", non-Lua functions raise "Lua function expected", indexes below 1 raise "Constant index starts at 1", and indexes past the available constants raise "Constant index out of range". debug.setconstant is an alias.
Call it with 3 parameter(s): target, 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 Proto constant in a Lua closure or stack level.
local function target()
return "before"
end
print(getconstant(target, 1))
setconstant(target, 1, "after")
print(getconstant(target, 1))
debug.setconstant(target, 1, "done")
print(getconstant(target, 1))