debugLuaLuau

The 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
debug.infoLuau
Returns information about a stack frame or function
debug.tracebackLua
Returns the call stack as a string

debug.infoLuau

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): ...any

Given 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:

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.

Input
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()}`)
Output
greet
1 parameter, variadic: true
called on line 12

debug.tracebackLua

function debug.traceback(co: thread, msg: string?, level: number?): string
function debug.traceback(msg: string?, level: number?): string

Returns 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.