debug.getupvalue Synchronous

  • getupvalue

Read the value captured in one upvalue slot of a Luau function. It is useful for checking the state a closure carries without calling it.

Syntax
Luau
debug.getupvalue(target: Function | number, index: number) -> any

Parameters

Function parameters
ParameterTypeDescription
targetFunction | numberA Luau function or visible stack level.
indexnumberOne-based upvalue slot.

Returns

any

The captured value.

Example

Example
Luau
local count = 0
local function nextCount() count += 1; return count end
print(debug.getupvalue(nextCount, 1)) -- 0
Kawaii documentation