Debug

getupvalues

Returns all upvalues from a Lua function or stack level as a one-based array table.

Syntax

getupvalues(target: function | number): table
Aliases debug.getupvalues

Arguments

NameTypeDescription
targetfunction | numberLua function or stack level whose upvalues are returned.

Returns

NameTypeDescription
upvaluestableOne-based array table containing the function upvalues. Empty when none are present.

Description

Returns all upvalues from a Lua function or stack level as a one-based array table. Invalid stack levels raise "Level out of range", and non-Lua functions raise "Lua function expected". debug.getupvalues is an alias.

Call it with 1 parameter(s): target. The argument table explains which values are required and which ones only refine the behavior.

It returns upvalues (table). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Read all upvalues from a Lua closure or stack level.

local first = "one"
local second = "two"

local function target()
    return first, second
end

local upvalues = getupvalues(target)

for index, value in ipairs(upvalues) do
    print(index, value)
end

print(#debug.getupvalues(target))