Library
debug
This library provides functions useful for debugging and profiling code.
About debug
Provides a few basic functions for debugging code in Roblox. Unlike the
debug library found in Lua natively, this version has been heavily
sandboxed.
Functions 11
traceback
(message: string = , level: number = 1) → stringReturns a string of undefined format that describes the current function call stack.Returns a traceback of the current function call stack as a string; in other words, a description of the functions that have been called up to this point. During debugging, this behaves like an error stack trace but does not stop execution of the script.
The
levelparameter specifies what level of the call stack to consider, with1being the call ofdebug.tracebackitself,2being the call of the function callingdebug.traceback, and so on. See the code sample below for an example of sequential function calls.Note that this function will often return inaccurate results (compared to the original source code) and that the format of the returned traceback may change at any time. You should not parse the return value for specific information such as script names or line numbers.
The following example includes sequential function calls;
fnB()is called, and it callsfnA()which then callsdebug.traceback.local function fnA() print(debug.traceback("Specific moment during fnA()")) end local function fnB() fnA() end -- Call function fnB() to begin traceback fnB()traceback
(thread: thread, message: string = , level: number = 1) → stringReturns a string of undefined format that describes the current function call stack.Returns a traceback of the current function call stack as a string; in other words, a description of the functions that have been called up to this point. During debugging, this behaves like an error stack trace but does not stop execution of the script.
The
levelparameter specifies what level of the call stack to consider, with1being the call ofdebug.tracebackitself,2being the call of the function callingdebug.traceback, and so on. See the code sample below for an example of sequential function calls.Note that this function will often return inaccurate results (compared to the original source code) and that the format of the returned traceback may change at any time. You should not parse the return value for specific information such as script names or line numbers.
The following example includes sequential function calls;
fnB()is called, and it callsfnA()which then callsdebug.traceback.local function fnA() print(debug.traceback("Specific moment during fnA()")) end local function fnB() fnA() end -- Call function fnB() to begin traceback fnB()info
(level: number, options: string) → TupleTraverses the entire stack of current thread and returns a string containing the call stack of target level details.Allows programmatic inspection of the call stack. This function differs from
debug.tracebackin that it guarantees the format of the data it returns. This is useful for general logging and filtering purposes as well as for sending the data to systems expecting structured input, such as crash aggregation.local function fnA() -- Output source identifier ("s") and line ("l") at levels 1 and 2 print(debug.info(1, "sl")) --> fnA() 3 print(debug.info(2, "sl")) --> fnA() 7 end fnA()Note that this function is similar to debug.getinfo, an unavailable part of the standard Lua library which serves a similar purpose.
info
(function: function, options: string) → TupleTraverses the entire stack of current thread and returns a string containing the call stack of target function details.Allows programmatic inspection of the call stack. This function differs from
debug.tracebackin that it guarantees the format of the data it returns. This is useful for general logging and filtering purposes as well as for sending the data to systems expecting structured input, such as crash aggregation.local function fnA() end local function fnB() end -- Output line ("l"), name ("n"), and identifier ("f") for both fnA() and fnB() print(debug.info(fnA, "lnf")) --> 1 fnA function: 0x75e3d3c398a81252 print(debug.info(fnB, "lnf")) --> 5 fnB function: 0x6022a6dc5ccf4ab2Note that this function is similar to debug.getinfo, an unavailable part of the standard Lua library which serves a similar purpose.
info
(thread: thread, level: number, options: string) → TupleTraverses the entire stack of target thread and returns a string containing the call stack of target level details.Allows programmatic inspection of the call stack. This function differs from
debug.tracebackin that it guarantees the format of the data it returns. This is useful for general logging and filtering purposes as well as for sending the data to systems expecting structured input, such as crash aggregation.local function fnA() -- Output source identifier ("s") and line ("l") at levels 1 and 2 print(debug.info(1, "sl")) --> fnA() 3 print(debug.info(2, "sl")) --> fnA() 7 end fnA()Note that this function is similar to debug.getinfo, an unavailable part of the standard Lua library which serves a similar purpose.
profilebegin
(label: string) → ()Starts profiling for a label.Starts profiling for a MicroProfiler label.
profileend
() → ()Stops profiling for the most recent label thatdebug.profilebeginopened.Stops profiling for the most recent MicroProfiler label that
debug.profilebeginopened.getmemorycategory
() → stringReturns the name of the current thread's active memory category.setmemorycategory
(tag: string) → stringAssigns a custom tag to the current thread's memory category.Assigns a custom tag name to the current thread's memory category in the Developer Console. Useful for analyzing memory usage of multiple threads in the same script which would otherwise be grouped together under the same tag/name. Returns the name of the current thread's previous memory category.
resetmemorycategory
() → ()Resets the tag assigned bydebug.setmemorycategoryto the automatically assigned value (typically, the script name).dumpcodesize
() → ()Displays a table of native code size of individual functions and scripts.Displays a table of native code size of individual functions and scripts. This function is only available in the Command Bar in Studio. More details can be found on the Native Code Generation page.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.