Syntax
getproto(target: function | number, index: number, active?: boolean): function | tabledebug.getprotoArguments
| Name | Type | Description |
|---|---|---|
target | function | number | Lua function or stack level whose nested functions are inspected. |
index | number | One-based nested function index. |
active? | boolean | When true, returns live closures for the selected nested function instead of a standalone function. |
Returns
| Name | Type | Description |
|---|---|---|
proto | function | table | Nested function when active is false or omitted, or a table of live closures when active is true. |
Description
Returns a nested Lua function by one-based index. target must be a Lua function or stack level number. Invalid stack levels raise "Level out of range", non-Lua functions raise "Lua function expected", and indexes outside the nested function range raise "index out of bounds". When active is true, returns currently live closures for that nested function instead. debug.getproto is an alias.
Call it with 3 parameter(s): target, index, active. The argument table explains which values are required and which ones only refine the behavior.
It returns proto (function | table). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Read a nested Proto as a cloned closure, or list live closures for that nested Proto.
local function outer()
local function inner()
return "ready"
end
return inner
end
local proto = getproto(outer, 1)
local active = getproto(outer, 1, true)
print(type(proto))
print(#active)
print(type(debug.getproto(outer, 1)))