parrotcode: Lua Debug Library | |
Contents | Language Implementations | Lua |
lib/luadebug.pir - Lua Debug Library
This library provides the functionality of the debug interface to Lua programs. You should exert care when using this library. The functions provided here should be used exclusively for debugging and similar tasks, such as profiling. Please resist the temptation to use them as a usual programming tool: They can be very slow. Moreover, several of its functions violate some assumptions about Lua code (e.g., that variables local to a function cannot be accessed from outside or that userdata metatables cannot be changed by Lua code) and therefore can compromise otherwise secure code.
All functions in this library are provided inside the debug
table.
See "Lua 5.1 Reference Manual", section 5.9 "The Debug Library".
debug.debug ()
cont
finishes this function,
so that the caller continues its execution.debug.debug
are not lexically nested within any function,
and so have no direct access to local variables.debug.getfenv (o)
o
.debug.gethook ()
debug.sethook
function).debug.getinfo (function [, what])
function
,
which means the function running at level function
of the call stack: 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.lua_getinfo
,
with the string what
describing which fields to fill in.
The default for what
is to get all information available.
If present,
the option `f
´ adds a field named func
with the function itself.debug.getinfo(1,"n").name
returns a name of the current function,
if a reasonable name can be found,
and debug.getinfo(print)
returns a table with all available information about the print
function.debug.getlocal (level, local)
local
of the function at level level
of 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 a level
out of range.
(You can call debug.getinfo
to check whether the level is valid.)(
´ (open parentheses) represent internal variables (loop control variables,
temporaries,
and C function locals).debug.getmetatable (object)
object
or nil if it does not have a metatable.debug.getregistry ()
debug.getupvalue (func, up)
up
of the function func
.
The function returns nil if there is no upvalue with the given index.debug.setfenv (object, table)
object
to the given table
.debug.sethook (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"
"r"
"l"
count
different from zero,
the hook is called after every count
instructions.debug.sethook
turns off the hook."call"
,
"return"
(or "tail return"
),
"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.debug.setlocal (level, local, value)
value
to the local variable with index local
of the function at level level
of the stack.
The function returns nil if there is no local variable with the given index,
and raises an error when called with a level
out of range.
(You can call getinfo
to check whether the level is valid.) Otherwise,
it returns the name of the local variable.debug.setmetatable (object, table)
object
to the given table
(which can be nil).debug.setupvalue (func, up, value)
value
to the upvalue with index up
of the function func
.
The function returns nil if there is no upvalue with the given index.
Otherwise,
it returns the name of the upvalue.debug.traceback ([message])
message
string is appended at the beginning of the traceback.
This function is typically used with xpcall
to produce better error messages.Francois Perrad
|