debug.setupvalue
Writes an upvalue. Global: setupvalue.
Syntax
debug.setupvalue(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.setupvalue 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.
The aliases setupval(func, index, value) resolve to the same implementation.
Example
local value = 10
local function f() return value end
debug.setupvalue(f, 1, 99)
print(f())
Notes
- Aliases:
setupval(func, index, value). - Writing protos, constants or upvalues can corrupt a running function; test changes carefully.