debug.getinfo

Gets information about a function or stack level.

Syntax

debug.getinfo(func_or_level: function | number | ProtoProxy) -> table

Parameters

ParameterTypeDescription
func_or_levelfunction, number, or ProtoProxyFunction, stack level, or nested prototype

Returns

TypeDescription
tableInformation about target

Description

debug.getinfo returns a table with information about a function or the function at a given stack level.

Info Fields

FieldDescription
nameFunction name, or an empty string
sourceSource identifier
short_srcShort source name
whatLua, C, or main
currentlineCurrent line, or the runtime sentinel for a non-active function
nupsNumber of upvalues
numparamsNumber of parameters
is_vararg1 for a variadic function, otherwise 0
funcFunction or ProtoProxy passed in

Example

local function myFunc()
    return "hello"
end

local info = debug.getinfo(myFunc)
print("Name:", info.name)
print("Source:", info.short_src)
print("Current line:", info.currentline)

-- Get info for current function
local currentInfo = debug.getinfo(1)
print("Current function:", currentInfo.name)