Skip to content
Debug libraryReference

debug.getproto

Represents inspection of a function prototype.

Aliasesgetproto

Details#

Inspects a nested Luau prototype at a one-based index; parent may also be a positive active stack level. With active=false (the default), returns an inspection closure with prototype metadata, not the original executable body. With active=true, returns existing live closures that share the nested prototype; an empty table is valid. Native functions and invalid indices raise errors. getproto is an alias.

Signature#

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

Parameters#

ParameterTypeDescription
parentfunction | numberLuau parent function or positive stack level.
indexnumberOne-based immediate nested-prototype index.
activeoptionalbooleanFind live matching closures; default false.

Returns#

An inspection function, or an array of live closures when active=true.

Examples#

Example

Luau
local chunk = assert(loadstring("return function() return 42 end"))
local child = chunk() -- keep a live reference
local matches = debug.getproto(chunk, 1, true)
print(type(matches), type(child)) -- table function
for _, closure in ipairs(matches) do
    print(closure == child)
end