debug.getinfo
Gets information about a function or stack level.
Syntax
debug.getinfo(func_or_level: function | number | ProtoProxy) -> tableParameters
| Parameter | Type | Description |
|---|---|---|
func_or_level | function, number, or ProtoProxy | Function, stack level, or nested prototype |
Returns
| Type | Description |
|---|---|
table | Information about target |
Description
debug.getinfo returns a table with information about a function or the function at a given stack level.
Info Fields
| Field | Description |
|---|---|
name | Function name, or an empty string |
source | Source identifier |
short_src | Short source name |
what | Lua, C, or main |
currentline | Current line, or the runtime sentinel for a non-active function |
nups | Number of upvalues |
numparams | Number of parameters |
is_vararg | 1 for a variadic function, otherwise 0 |
func | Function 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)Related Functions
debug.getcallstack- Get full call stackdebug.validlevel- Check if level is valid