debug
The debug library of LuaJIT 2.1, restricted for the sandboxed VM. It gives access to stack frames, locals, upvalues, metatables and hooks.
Script time limits
The client uses its own hook to enforce script time limits: 2000 ms for the main chunk and 100 ms per frame. A script that replaces the hook with debug.sethook can be stopped at the next check anyway, and timeouts cannot be caught with pcall.
debug.debug is removed
debug.debug (the interactive prompt) does not exist in this VM.
Functions
debug.getfenv(o: any): table | nil
debug.getfenv(o: any): table | nil
- Returns the environment table of
o(function, userdata or thread).
debug.gethook(co?: thread): function, string, number
debug.gethook(co?: thread): function, string, number
- Returns the current hook function, the hook mask string and the hook count.
debug.getinfo(f: function | number, what?: string = "flnSu"): table | nil
debug.getinfo(f: function | number, what?: string = "flnSu"): table | nil
- Returns a table describing a function.
fis a function, or a stack level (0 isgetinfoitself, 1 the caller). Returnsnilif the level is out of range. - A thread can be given as first argument:
debug.getinfo(co, f, what). whatselects fields:ngivesnameandnamewhat;Sgivessource,short_src,what,linedefined,lastlinedefined;lgivescurrentline;ugivesnups;fgivesfunc;Lgivesactivelines.
local info = debug.getinfo(1, "Sl")
print(info.short_src, info.currentline)
debug.getlocal(level: number | function, index: number): string, any
debug.getlocal(level: number | function, index: number): string, any
- Returns the name and value of local variable number
indexat stack levellevel, ornilif there is none. - With a function instead of a level, returns only the name of the parameter
index. - A thread can be given as first argument.
debug.getmetatable(obj: any): table | nil
debug.getmetatable(obj: any): table | nil
- Returns the metatable of
obj, ignoring any__metatablefield.
debug.getregistry(): table
debug.getregistry(): table
- Returns the Lua registry table.
debug.getupvalue(f: function, up: number): string, any
debug.getupvalue(f: function, up: number): string, any
- Returns the name and value of upvalue number
upoff, or nothing if there is none.
debug.setfenv(o: any, env: table): any
debug.setfenv(o: any, env: table): any
- Sets the environment of
o(function, userdata or thread) and returnso.
debug.sethook(hook?: function, mask?: string, count?: number)
debug.sethook(hook?: function, mask?: string, count?: number)
- Installs
hook.maskmay contain"c"(call),"r"(return) and"l"(new line);countfires the hook everycountinstructions. - Called with no arguments, removes the hook.
- See the warning above: the client keeps enforcing its time limits regardless.
debug.setlocal(level: number, index: number, value: any): string | nil
debug.setlocal(level: number, index: number, value: any): string | nil
- Assigns
valueto local variable numberindexat stack levellevel. Returns the variable name, ornilif there is no such variable.
debug.setmetatable(obj: any, mt: table | nil): any
debug.setmetatable(obj: any, mt: table | nil): any
- Sets the metatable of any value, including numbers, strings and functions. Returns
obj.
debug.setupvalue(f: function, up: number, value: any): string | nil
debug.setupvalue(f: function, up: number, value: any): string | nil
- Assigns
valueto upvalue numberupoff. Returns the upvalue name, ornilif there is none.
debug.traceback(co?: thread, message?: any, level?: number = 1): string
debug.traceback(co?: thread, message?: any, level?: number = 1): string
- Returns a string with a stack traceback, prefixed by
messageand a newline whenmessageis a string. - If
messageis not a string and notnil, returns it unchanged. - Often used as the handler of
xpcall.
print(debug.traceback("here"))
debug.upvalueid(f: function, n: number): userdata
debug.upvalueid(f: function, n: number): userdata
- Returns a unique identifier for upvalue
noff. Two closures sharing an upvalue return the same identifier.
debug.upvaluejoin(f1: function, n1: number, f2: function, n2: number)
debug.upvaluejoin(f1: function, n1: number, f2: function, n2: number)
- Makes upvalue
n1of closuref1refer to upvaluen2of closuref2.