AcediaDocumentation

debug.getproto

Reads a nested prototype handle or finds its live closures.

The default result is an inactive inspection handle. Calling it returns nil without executing the nested function; use it to read constants, upvalues, and children. active=true returns a list of live closures, which can be empty.

debug.getproto(subject: function | number, index: number, active: boolean?): function | {function}

Parameters

ParameterTypeDescription
subjectfunction | numberLua function or reachable stack level. C functions are rejected by prototype readers.
indexnumberOne-based immediate child prototype index.
activeboolean?Defaults to false. true returns matching live closures.

Example

local function outer()
    local function inner() return 1 end
    return inner
end
local live = outer()
local matches = debug.getproto(outer, 1, true)
print(#matches)

Example output

1

Errors: An out-of-range index raises an error.

Aliases: getproto.

On this page