Debug.traceback doesn't mention the three arguments it can take

https://developer.roblox.com/en-us/api-reference/lua-docs/debug

There is no mention of the arguments which you can pass to debug.traceback

First argument

The first argument is an optional thread, so you can get the stack trace of another thread.
If the first argument isn’t a thread then it will assume it is the running thread, which will make the first argument act like the second argument and the second argument act like the third argument.

debug.traceback(coroutine.running(),message,level)
--is the same thing as
debug.traceback(message,level)
--and you can pass other threads
local thread = coroutine.create(function()end)
debug.traceback(thread,message,level)
Second argument

The second argument specifies what to be attached to the start of the traceback.
There will automatically be a newline character after the message if the second argument is provided.
If the second argument is nil, no message will be added. If the second argument isn’t nil and not a string/number then debug.traceback will error.

debug.traceback""
--forces newline character infront of the traceback
debug.traceback"traceback:"

image

Third Argument

The third argument controls the level to start the traceback.
The default level is 1, starting the traceback from where debug.traceback is being called.
If level is anything other than nil or a number, debug.traceback will error.

local function f()
    debug.traceback(nil,1)
    --acts the same as
    debug.traceback()

    debug.traceback(nil,2)
    --makes the function call not show up in the traceback
end
f()

With level 1:
image
With level 2:
image

The traceback from debug.traceback also ends with a new line, which isn’t specifically stated.

6 Likes

Any word on this being added?