debug.setconstant
Writes a constant. Global: setconstant.
Syntax
debug.setconstant(func: any, index: number, value: any) -> nil
Parameters
| Parameter | Type | Description |
|---|---|---|
func | any | The func value used by the call. |
index | number | A one-based index. |
value | any | The value to apply. |
Returns
| Type | Description |
|---|---|
nil | This function does not return a value. |
Description
debug.setconstant is part of the Debug library. The debug library exposes the internals of the active Luau state, including protos, constants, upvalues and stack frames.
The change is applied directly to the live target, so later reads observe the updated value.
Example
local function f() return 123 end
debug.setconstant(f, 1, 456)
print(f())
Notes
- Writing protos, constants or upvalues can corrupt a running function; test changes carefully.