debug
The Debug Library.
All functions in this library are provided inside the debug table. All functions that operate over a thread have an optional first argument which is the thread to operate over. The default is always the current thread.
debug
debug.debug() | Enters an interactive mode with the user, running each string that the user enters. |
debug.getfenv(o) | Returns the environment of object o . |
debug.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.sethook function). |
debug.getinfo(thread, what) | Returns a table with information about a function. |
debug.getlocal(thread, level) | This function returns the name and the value of the local variable with
index local of the function at level level of the stack. |
debug.getmetatable(object) | Returns the metatable of the given object or nil if it does not have
a metatable. |
debug.getregistry() | Returns the registry table (see §3.5). |
debug.getupvalue(func, up) | This function returns the name and the value of the upvalue with index
up of the function func . |
debug.setfenv(object, table) | Sets the environment of the given object to the given table . |
debug.sethook(thread, hook, mask, count) | Sets the given function as a hook. |
debug.setlocal(thread, level, value) | This function assigns the value value to the local variable with
index local of the function at level level of the stack. |
debug.setmetatable(object, table) | Sets the metatable for the given object to the given table (which
can be nil). |
debug.setupvalue(func, up, value) | This function assigns the value value to the upvalue with index up
of the function func . |
debug
debug.debug()
cont
finishes this function, so that the caller continues its execution.
Note that commands for debug.debug
are not lexically nested within any
function, and so have no direct access to local variables.
debug.getfenv(o)
o
.
o
:
debug.gethook(thread)
debug.sethook
function).
thread
:
debug.getinfo(thread, what)
function
,
which means the function running at level function
of the call stack
of the given thread: level 0 is the current function (getinfo
itself);
level 1 is the function that called getinfo
; and so on. If function
is a number larger than the number of active functions, then getinfo
returns nil.
The returned table can contain all the fields returned by lua_getinfo
,
with the string what
describing which fields to fill in. The default for
what
is to get all information available, except the table of valid
lines. If present, the option 'f
' adds a field named func
with
the function itself. If present, the option 'L
' adds a field named
activelines
with the table of valid lines.
For instance, the expression debug.getinfo(1,"n").name
returns a table
with a name for the current function, if a reasonable name can be found,
and the expression debug.getinfo(print)
returns a table with all available
information about the print
function.
thread
:
what
:
debug.getlocal(thread, level)
local
of the function at level level
of the stack.
level
out
of range. (You can call debug.getinfo
to check whether the level is valid.)
Variable names starting with '(
' (open parentheses) represent internal
variables (loop control variables, temporaries, and C function locals).
thread
:
level
:
debug.getmetatable(object)
object
or nil if it does not have
a metatable.
object
:
debug.getregistry()
debug.getupvalue(func, up)
up
of the function func
.
func
:
up
:
debug.setfenv(object, table)
object
to the given table
.
object
.
object
:
table
:
debug.sethook(thread, hook, mask, count)
mask
and the number
count
describe 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 count
different from zero, the hook is called after every count
instructions.
When called without arguments, debug.sethook
turns 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 call getinfo
with level 2 to
get more information about the running function (level 0 is the getinfo
function, 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 to
getinfo
will return invalid data.
thread
:
hook
:
mask
:
count
:
debug.setlocal(thread, level, value)
value
to the local variable with
index local
of the function at level level
of the stack.
level
out of range. (You can call getinfo
to check whether the level is valid.) Otherwise, it returns the name of
the local variable.
thread
:
level
:
value
:
debug.setmetatable(object, table)
object
to the given table
(which
can be nil).
object
:
table
:
debug.setupvalue(func, up, value)
value
to the upvalue with index up
of the function func
.
func
:
up
:
value
: