debugInherited from Lua 5.1's standard library.
LuaAdded by Luau: debug.info
Luau
debug.infoThe debug library inspects the call stack through two functions: debug.info tells you where a function was defined or which line a stack frame is on, and debug.traceback formats the whole stack as text for error reports and logs.
Both accept an optional thread as their first argument to inspect that coroutine's stack instead of the current one. Stack levels count up from the caller: level 1 is the function that calls into the library, level 2 is the function that called it, and so on.
Summary
function debug.info(co: thread, level: number, s: string): ...any function debug.info(level: number, s: string): ...any function debug.info(f: (...any) -> ...any, s: string): ...anydebug.infoAdded by Luau 0.501 or earlier.
Luau- Returns information about a stack frame or function
function debug.traceback(co: thread, msg: string?, level: number?): string function debug.traceback(msg: string?, level: number?): stringdebug.tracebackInherited from Lua 5.1's standard library.
Lua- Returns the call stack as a string
debug.infoAdded by Luau 0.501 or earlier.
Luau
function debug.info(co: thread, level: number, s: string): ...any
function debug.info(level: number, s: string): ...any
function debug.info(f: (...any) -> ...any, s: string): ...anyGiven a stack level or a function, and a string s that says what to read, returns information about that stack frame or function. Each character of s adds results in the order the characters appear:
sreturns the path of the function's source.lreturns the line the stack frame is on, or the line where the function is defined when you pass a function.nreturns the function's name, or an empty string when it has none.freturns the function itself.areturns two results: the number of parameters the function declares and whether it takes....
For example, debug.info(2, "sln") returns the source, current line and name of the function that called the current one.
A level past the bottom of the stack returns nothing. A negative level, an unknown character or a character used twice in s raises an error.
const function greet(name: string, ...: string)
print(`hello {name}`)
end
print(debug.info(greet, "n"))
const count, variadic = debug.info(greet, "a")
print(`{count} parameter, variadic: {variadic}`)
const function caller_line(): number
return debug.info(2, "l")
end
print(`called on line {caller_line()}`)greet 1 parameter, variadic: true called on line 12
debug.tracebackInherited from Lua 5.1's standard library.
Lua
function debug.traceback(co: thread, msg: string?, level: number?): string
function debug.traceback(msg: string?, level: number?): stringReturns the call stack of the given thread, or of the current one, as a string that starts at level. When you pass msg, the string starts with it on a separate line above the call stack.
The level defaults to 1 for the current thread and to 0 for another thread. A negative level raises an error.
The format is meant for people to read and can change between versions. Don't parse it.