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.
Luau
debug.getupvalue(target: Function | number, index: number) -> anyParameters
| Parameter | Type | Description |
|---|---|---|
target | Function | number | A Luau function or visible stack level. |
index | number | One-based upvalue slot. |
Returns
anyThe captured value.
Example
Luau
local count = 0
local function nextCount() count += 1; return count end
print(debug.getupvalue(nextCount, 1)) -- 0