Garry's Mod Wiki

debug

The debug library is intended to help you debug your scripts, however it also has several other powerful uses. Some builtin debug function were removed in GMod due to security reasons

Methods

debug.debug()
We advise against using this. It may be changed or removed in a future update. This only works on the source dedicated server. Enters an interactive mode with the user, running each string that the user enters. Using simple commands and other debug facilities, the user can inspect global and local variables, change their values, evaluate expressions, and so on. A line containing only the word cont finishes this function, so that the caller continues its execution. Commands for debug. debug are not lexically nested within any function, and so have no direct access to local variables. To exit this interactive mode, you can press Ctrl + Z then Enter OR type the word 'cont' on a single line and press enter.
table debug.getfenv( table object )
We advise against using this. It may be changed or removed in a future update. Returns the environment of the passed object. This can be set with debug. setfenv
function, string, number debug.gethook( thread thread = nil )
We advise against using this. It may be changed or removed in a future update. Returns the current hook settings of the passed thread. The thread argument can be omitted. This is completely different to gamemode hooks. More information on hooks can be found at http://www. lua. org/pil/23. 2. html. This function will simply return the function, mask, and count of the last called debug. sethook.
table debug.getinfo( function funcOrStackLevel, string fields = "flnSu>", function function )
Returns debug information about a function.
string, any debug.getlocal( thread thread = Current thread, number level, number index )
We advise against using this. It may be changed or removed in a future update. Gets the name and value of a local variable indexed from the level. When a function has a tailcall return, you cannot access the locals of this function.
table debug.getmetatable( any object )
We advise against using this. It may be changed or removed in a future update. Returns the metatable of an object. This function ignores the metatable's __metatable field.
We advise against using this. It may be changed or removed in a future update. This function will return an empty table. If you get an error because of this see the example below for a workaround Returns the internal Lua registry table. The Lua registry is used by the engine and binary modules to create references to Lua values. The registry contains every global ran and used in the Lua environment. Avoid creating entries into the registry with a number as the key, as they are reserved for the reference system. Improper editing of the registry can result in unintended side effects, including crashing the game.
string, any debug.getupvalue( function func, number index )
We advise against using this. It may be changed or removed in a future update. Used for getting variable values in an index from the passed function. This does nothing for C functions.
table debug.setfenv( table object, table env )
We advise against using this. It may be changed or removed in a future update. Sets the environment of the passed object.
debug.sethook( thread thread, function hook, string mask, number count )
We advise against using this. It may be changed or removed in a future update. Sets the given function as a Lua hook. This is completely different to gamemode hooks. The thread argument can be completely omitted and calling this function with no arguments will remove the current hook. This is used by default for infinite loop detection. More information on hooks can be found at http://www. lua. org/pil/23. 2. html and https://www. gammon. com. au/scripts/doc. php?lua=debug. sethook Hooks are not always ran when code that has been compiled by LuaJIT's JIT compiler is being executed, this is due to Intermediate Representation internally storing constantly running bytecode for performance reasons.
string debug.setlocal( thread thread = Current Thread, number level, number index, any value = nil )
This function was removed due to security concerns. Sets a local variable's value.
boolean debug.setmetatable( any object, table metatable )
We advise against using this. It may be changed or removed in a future update. Sets the object's metatable. Unlike setmetatable, this function works regardless of whether the first object passed is a valid table or not; this function even works on primitive datatypes such as numbers, functions, and even nil.
string debug.setupvalue( function func, number index, any val = nil )
This function was removed due to security concerns. Sets the variable indexed from func
debug.Trace()
Prints out the lua function call stack to the console.
string debug.traceback( thread thread = current thread, string message = "nil", number level = 1 )
We advise against using this. It may be changed or removed in a future update. Returns a full execution stack trace.
number debug.upvalueid( function func, number index )
This function was removed due to security concerns. Returns an unique identifier for the upvalue indexed from func
debug.upvaluejoin( function f1, number n1, function f2, number n2 )
This function was removed due to security concerns. Make the n1-th upvalue of the Lua closure f1 refer to the n2-th upvalue of the Lua closure f2.