debug.getcallstack

Gets visible call frames from the current thread or another thread.

Syntax

debug.getcallstack(thread?: thread) -> {{func: function, currentline: number?}}

Parameters

ParameterTypeDescription
threadthread?Thread to inspect; defaults to the current thread

Returns

TypeDescription
tableArray of call stack entries

Description

debug.getcallstack returns non-hidden frames. Each entry contains the function and, for Luau frames, the current source line. OTH hook frames are followed into their linked original thread.

Example

local function innerFunc()
    local stack = debug.getcallstack()
    for i, entry in ipairs(stack) do
        local info = debug.getinfo(entry.func)
        print(i, info.name or "anonymous", entry.currentline)
    end
end

local function outerFunc()
    innerFunc()
end

outerFunc()

Entry Fields

FieldDescription
funcFunction running in this frame
currentlineCurrent source line for a Luau frame; absent for C frames