Volt

debug.getprotos

Gets all protos (nested functions) from a function.

Syntax

debug.getprotos(func: function | number) -> table

Parameters

ParameterTypeDescription
funcfunction or numberThe function or stack level

Returns

TypeDescription
tableAn array of all protos in the function

Description

debug.getprotos returns a table containing all nested function definitions within a function.

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, proto()) -- Calls each nested function
end
--[[
Output:
1  1
2  2
3  3
]]

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

On this page