Volt

debug.getinfo

Gets information about a function or stack level.

Syntax

debug.getinfo(func_or_level: function | number, what: string?) -> table

Parameters

ParameterTypeDescription
func_or_levelfunction/numberFunction or stack level
whatstring(Optional) What info to return

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

FieldWhatDescription
namenFunction name
sourceSSource identifier
short_srcSShort source name
whatS"Lua", "C", or "main"
currentlinelCurrent line
linedefinedSLine where definition starts
lastlinedefinedSLine where definition ends
nupsuNumber of upvalues
nparamsuNumber of parameters
funcfThe function itself

Example

local function myFunc()
    return "hello"
end

local info = debug.getinfo(myFunc)
print("Name:", info.name)
print("Source:", info.short_src)
print("Line defined:", info.linedefined)

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

On this page