Module debug
getting runtime debug information.
Functions
- debug ()
-
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
contfinishes this function, so that the caller continues its execution. Note that commands fordebug.debugare not lexically nested within any function, and so have no direct access to local variables. - getfenv (o)
-
Returns the environment of object
o. - gethook (thread)
-
Returns the current hook settings of the thread, as three values: the
current hook function, the current hook mask, and the current hook count
(as set by the
debug.sethookfunction). - getinfo (thread, function, what)
-
Returns a table with information about a function. You can give the
function directly, or you can give a number as the value of
function, which means the function running at levelfunctionof the call stack of the given thread: level 0 is the current function (getinfoitself); level 1 is the function that calledgetinfo; and so on. Iffunctionis a number larger than the number of active functions, thengetinforeturns nil.threadandwhatare optional.The returned table can contain all the fields returned by
lua_getinfo, with the stringwhatdescribing which fields to fill in. The default forwhatis to get all information available, except the table of valid lines. If present, the option ‘f’ adds a field namedfuncwith the function itself. If present, the option ‘L’ adds a field namedactivelineswith the table of valid lines. For instance, the expressiondebug.getinfo(1,"n").namereturns a table with a name for the current function, if a reasonable name can be found, and the expressiondebug.getinfo(print)returns a table with all available information about theprintfunction. - getlocal (thread, level, local)
-
This function returns the name and the value of the local variable with
index
localof the function at levellevelof the stack. (The first parameter or local variable has index 1, and so on, until the last active local variable.) The function returns nil if there is no local variable with the given index, and raises an error when called with alevelout of range. (You can calldebug.getinfoto check whether the level is valid.) Variable names starting with ‘(’ (open parentheses) represent internal variables (loop control variables, temporaries, and C function locals). - getmetatable (object)
-
Returns the metatable of the given
objector nil if it does not have a metatable. - getregistry ()
- Returns the registry table (see ยง3.5).
- getupvalue (func, up)
-
This function returns the name and the value of the upvalue with index
upof the functionfunc. The function returns nil if there is no upvalue with the given index. - setfenv (object, table)
-
Sets the environment of the given
objectto the giventable. Returnsobject. - sethook (thread, hook, mask, count)
-
Sets the given function as a hook. The string
maskand the numbercountdescribe when the hook will be called. The string mask may have the following characters, with the given meaning:-
"c": the hook is called every time Lua calls a function; -
"r": the hook is called every time Lua returns from a function; -
"l": the hook is called every time Lua enters a new line of code.
With a
countdifferent from zero, the hook is called after everycountinstructions.When called without arguments,
debug.sethookturns off the hook.When the hook is called, its first parameter is a string describing the event that has triggered its call:
"call","return"(or"tail return", when simulating a return from a tail call),"line", and"count". For line events, the hook also gets the new line number as its second parameter. Inside a hook, you can callgetinfowith level 2 to get more information about the running function (level 0 is thegetinfofunction, and level 1 is the hook function), unless the event is"tail return". In this case, Lua is only simulating the return, and a call togetinfowill return invalid data. -
- setlocal (thread, level, local, value)
-
This function assigns the value
valueto the local variable with indexlocalof the function at levellevelof the stack. The function returns nil if there is no local variable with the given index, and raises an error when called with alevelout of range. (You can callgetinfoto check whether the level is valid.) Otherwise, it returns the name of the local variable. - setmetatable (object, table)
-
Sets the metatable for the given
objectto the giventable(which can be nil). - setupvalue (func, up, value)
-
This function assigns the value
valueto the upvalue with indexupof the functionfunc. The function returns nil if there is no upvalue with the given index. Otherwise, it returns the name of the upvalue.