debug.getupvalue
Reads one captured variable of a Lua closure.
Syntax
debug.getupvalue(target: function | number, index: number) -> any
Also available as
getupvalueget_upvalue
Parameters
| Parameter | Type | Description |
|---|---|---|
target | function or number | Lua closure or visible caller level. |
index | number | One-based upvalue slot. |
Returns
| Type | Description |
|---|---|
any | Value in the selected upvalue slot. |
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. A valid upvalue can contain nil.
Example
local captured = {}
local function sample() return captured end
print(debug.getupvalue(sample, 1) == captured)
These are Game executor contracts. Check build requirements and session lifetimes before using them.
