ReferenceDebug

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

ParameterTypeDescription
targetfunction or numberLua closure or visible caller level.
indexnumberOne-based upvalue slot.

Returns

TypeDescription
anyValue 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.