debug.traceback

Returns a string with a traceback of the stack call

Prototype

s = debug.traceback ( [thread,] message [, level])

Description

Returns a string with a traceback of the stack call. An optional message string is prepended to the beginning of the traceback message.

function f ()
  function g ()
  print (debug.traceback ("traceback in g"))
  end -- g
  g ()
end -- f

f ()

 -->
 
traceback in g
stack traceback:
        stdin:3: in function `g'
        stdin:6: in function `f'
        stdin:1: in main chunk
        [C]: ?
You can optionally supply a thread (coroutine) to be traced. This is useful if you get an error after calling coroutine.resume.

An optional level number tells at which level to start the tracekback - the default is 1 which is the function calling traceback.

Lua functions

Topics