Library debug

Debug library.

Functions

isCalledBy( level, func ) Indicates whether the given function is the caller at the given stack level.
isCalledByAnyOf( level, funcs ) Indicates whether any of the given functions are the caller at the given stack level.
traceback( thread, message, stackLevel ) Provides the current stack traceback.


Functions

debug.isCalledBy( level, func )
Indicates whether the given function is the caller at the given stack level.

Environment:

Shared

Parameters:

  • level: The stack level above the current level to check (1 = current level).
  • func: The function to look for.

Return value:

    (boolean) True if the function at the given stack level is equal to the given function.
debug.isCalledByAnyOf( level, funcs )
Indicates whether any of the given functions are the caller at the given stack level.

Environment:

Shared

Parameters:

  • level: The stack level above the current level to check (1 = current level).
  • funcs: The functions to look for (a lookup table with function keys).

Return value:

    (boolean) True if the function at the given stack level is contained in the lookup (using rawget).
debug.traceback( thread, message, stackLevel )
Provides the current stack traceback.

Environment:

Shared

Parameters:

  • (thread?) thread: (Optional) The coroutine to get the traceback from.
  • (string?) message: (Optional) The message to include on the first line of the traceback (e.g. a caught error).
  • (number?) stackLevel: (Optional) The stack level to start the traceback from (1 = where debug.traceback() is called or where a coroutine last yielded/died).

Usage:

    -- Get a traceback starting at the current line 
    debug.traceback() 
     
    -- Get a traceback with a message starting at the caller. 
    debug.traceback( "Some error happened", 2 ) 
     
    -- Get a traceback from a coroutine. 
    debug.traceback( Thread ) 
     
    -- Get a traceback from a coroutine at a given level (0 = yield, error or return). 
    debug.traceback( Thread, "Some error happened", 2 )

Return value:

    (string) A string representing the current call stack, or the given message if it is not a string.

Valid XHTML 1.0!