debug.setupvalue
Changes one captured variable of a Lua closure.
Syntax
debug.setupvalue(target: function | number, index: number, value: any) -> ()
Also available as
setupvalueset_upvalue
Parameters
| Parameter | Type | Description |
|---|---|---|
target | function or number | Lua closure or visible caller level. |
index | number | One-based upvalue slot. |
value | any | New captured value. |
Description
Upvalues are variables captured from an enclosing scope. Indices start at 1 and are separate from constant and local-variable indices. Use debug.getupvalues to inspect the closure first. Invalid indices raise an error. Updating a shared captured variable can affect other closures using that variable.
Example
local captured = {}
local function sample() return captured end
debug.setupvalue(sample, 1, { changed = true })
print(sample().changed)
These are Game executor contracts. Check build requirements and session lifetimes before using them.
