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
| Parameter | Type | Description |
|---|---|---|
subject | function | number | Lua function or reachable stack level. C functions are rejected by prototype readers. |
index | number | One-based immediate child prototype index. |
active | boolean? | 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
1Errors: An out-of-range index raises an error.
Aliases: getproto.
