debug.getprotos

Gets all protos (nested functions) from a function.

Syntax

debug.getprotos(func: function | number | ProtoProxy) -> {ProtoProxy}

Parameters

ParameterTypeDescription
funcfunction, stack level, or ProtoProxyThe prototype to inspect

Returns

TypeDescription
tableAn array of ProtoProxy values for all nested prototypes

Description

debug.getprotos returns ProtoProxy values for nested functions. These values can be used with compatible debug functions, but cannot be called directly.

Example

local function container()
    local function a() return 1 end
    local function b() return 2 end
    local function c() return 3 end
    return a() + b() + c()
end

local protos = debug.getprotos(container)
print(#protos) -- 3

for i, proto in ipairs(protos) do
    print(i, typeof(proto), #debug.getconstants(proto))
end

Use Cases

  • Script analysis: Find all functions defined within a script
  • Hooking: Locate specific nested functions to hook
  • Debugging: Inspect the structure of complex functions