ves a name to the chunk, which is used for error messages and in debug information (see §3.8).
lua_newstate
[-0, +0, -]
lua_State *lua_newstate (lua_Alloc f, void *ud);
Creates a new, independent state.
Returns NULL
if cannot create the state
(due to lack of memory).
The argument f
is the allocator function;
Lua does all memory allocation for this state through this function.
The second argument, ud
, is an opaque pointer that Lua
simply passes to the allocator in every call.
lua_newtable
[-0, +1, m]
void lua_newtable (lua_State *L);
Creates a new empty table and pushes it onto the stack.
It is equivalent to lua_createtable(L, 0, 0)
.
lua_newthread
[-0, +1, m]
lua_State *lua_newthread (lua_State *L);
Creates a new thread, pushes it on the stack,
and returns a pointer to a lua_State
that represents this new thread.
The new state returned by this function shares with the original state
all global objects (such as tables),
but has an independent execution stack.
There is no explicit function to close or to destroy a thread. Threads are subject to garbage collection, like any Lua object.
lua_newuserdata
[-0, +1, m]
void *lua_newuserdata (lua_State *L, size_t size);
This function allocates a new block of memory with the given size, pushes onto the stack a new full userdata with the block address, and returns this address.
Userdata represent C values in Lua. A full userdata represents a block of memory. It is an object (like a table): you must create it, it can have its own metatable, and you can detect when it is being collected. A full userdata is only equal to itself (under raw equality).
When Lua collects a full userdata with a gc
metamethod,
Lua calls the metamethod and marks the userdata as finalized.
When this userdata is collected again then
Lua frees its corresponding memory.
lua_next
[-1, +(2|0), e]
int lua_next (lua_State *L, int index);
Pops a key from the stack,
and pushes a key-value pair from the table at the given index
(the "next" pair after the given key).
If there are no more elements in the table,
then lua_next
returns 0 (and pushes nothing).
A typical traversal looks like this:
/* table is in the stack at index 't' */ lua_pushnil(L); /* first key */ while (lua_next(L, t) != 0) { /* uses 'key' (at index -2) and 'value' (at index -1) */ printf("%s - %s\n", lua_typename(L, lua_type(L, -2)), lua_typename(L, lua_type(L, -1))); /* removes 'value'; keeps 'key' for next iteration */ lua_pop(L, 1); }
While traversing a table,
do not call lua_tolstring
directly on a key,
unless you know that the key is actually a string.
Recall that lua_tolstring
changes
the value at the given index;
this confuses the next call to lua_next
.
lua_Number
typedef double lua_Number;
The type of numbers in Lua.
By default, it is double, but that can be changed in luaconf.h
.
Through the configuration file you can change Lua to operate with another type for numbers (e.g., float or long).
lua_objlen
[-0, +0, -]
size_t lua_objlen (lua_State *L, int index);
Returns the "length" of the value at the given acceptable index:
for strings, this is the string length;
for tables, this is the result of the length operator ('#
');
for userdata, this is the size of the block of memory allocated
for the userdata;
for other values, it is 0.
lua_pcall
[-(nargs + 1), +(nresults|1), -]
int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);
Calls a function in protected mode.
Both nargs
and nresults
have the same meaning as
in lua_call
.
If there are no errors during the call,
lua_pcall
behaves exactly like lua_call
.
However, if there is any error,
lua_pcall
catches it,
pushes a single value on the stack (the error message),
and returns an error code.
Like lua_call
,
lua_pcall
always removes the function
and its arguments from the stack.
If errfunc
is 0,
then the error message returned on the stack
is exactly the original error message.
Otherwise, errfunc
is the stack index of an
error handler function.
(In the current implementation, this index cannot be a pseudo-index.)
In case of runtime errors,
this function will be called with the error message
and its return value will be the message returned on the stack by lua_pcall
.
Typically, the error handler function is used to add more debug
information to the error message, such as a stack traceback.
Such information cannot be gathered after the return of lua_pcall
,
since by then the stack has unwound.
The lua_pcall
function returns 0 in case of success
or one of the following error codes
(defined in lua.h
):
LUA_ERRRUN
:
a runtime error.
LUA_ERRMEM
:
memory allocation error.
For such errors, Lua does not call the error handler function.
LUA_ERRERR
:
error while running the error handler function.
lua_pop
[-n, +0, -]
void lua_pop (lua_State *L, int n);
Pops n
elements from the stack.
lua_pushboolean
[-0, +1, -]
void lua_pushboolean (lua_State *L, int b);
Pushes a boolean value with value b
onto the stack.
lua_pushcclosure
[-n, +1, m]
void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
Pushes a new C closure onto the stack.
When a C function is created,
it is possible to associate some values with it,
thus creating a C closure (see §3.4);
these values are then accessible to the function whenever it is called.
To associate values with a C function,
first these values should be pushed onto the stack
(when there are multiple values, the first value is pushed first).
Then lua_pushcclosure
is called to create and push the C function onto the stack,
with the argument n
telling how many values should be
associated with the function.
lua_pushcclosure
also pops these values from the stack.
The maximum value for n
is 255.
lua_pushcfunction
[-0, +1, m]
void lua_pushcfunction (lua_State *L, lua_CFunction f);
Pushes a C function onto the stack.
This function receives a pointer to a C function
and pushes onto the stack a Lua value of type function
that,
when called, invokes the corresponding C function.
Any function to be registered in Lua must
follow the correct protocol to receive its parameters
and return its results (see lua_CFunction
).
lua_pushcfunction
is defined as a macro:
#define lua_pushcfunction(L,f) lua_pushcclosure(L,f,0)
lua_pushfstring
[-0, +1, m]
const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
Pushes onto the stack a formatted string
and returns a pointer to this string.
It is similar to the C function sprintf
,
but has some important differences:
%%
' (inserts a '%
' in the string),
'%s
' (inserts a zero-terminated string, with no size restrictions),
'%f
' (inserts a lua_Number
),
'%p
' (inserts a pointer as a hexadecimal numeral),
'%d
' (inserts an int
), and
'%c
' (inserts an int
as a character).
lua_pushinteger
[-0, +1, -]
void lua_pushinteger (lua_State *L, lua_Integer n);
Pushes a number with value n
onto the stack.
lua_pushlightuserdata
[-0, +1, -]
void lua_pushlightuserdata (lua_State *L, void *p);
Pushes a light userdata onto the stack.
Userdata represent C values in Lua. A light userdata represents a pointer. It is a value (like a number): you do not create it, it has no individual metatable, and it is not collected (as it was never created). A light userdata is equal to "any" light userdata with the same C address.
lua_pushliteral
[-0, +1, m]
void lua_pushliteral (lua_State *L, const char *s);
This macro is equivalent to lua_pushlstring
,
but can be used only when s
is a literal string.
In these cases, it automatically provides the string length.
lua_pushlstring
[-0, +1, m]
void lua_pushlstring (lua_State *L, const char *s, size_t len);
Pushes the string pointed to by s
with size len
onto the stack.
Lua makes (or reuses) an internal copy of the given string,
so the memory at s
can be freed or reused immediately after
the function returns.
The string can contain embedded zeros.
lua_pushnil
[-0, +1, -]
void lua_pushnil (lua_State *L);
Pushes a nil value onto the stack.
lua_pushnumber
[-0, +1, -]
void lua_pushnumber (lua_State *L, lua_Number n);
Pushes a number with value n
onto the stack.
lua_pushstring
[-0, +1, m]
void lua_pushstring (lua_State *L, const char *s);
Pushes the zero-terminated string pointed to by s
onto the stack.
Lua makes (or reuses) an internal copy of the given string,
so the memory at s
can be freed or reused immediately after
the function returns.
The string cannot contain embedded zeros;
it is assumed to end at the first zero.
lua_pushthread
[-0, +1, -]
int lua_pushthread (lua_State *L);
Pushes the thread represented by L
onto the stack.
Returns 1 if this thread is the main thread of its state.
lua_pushvalue
[-0, +1, -]
void lua_pushvalue (lua_State *L, int index);
Pushes a copy of the element at the given valid index onto the stack.
lua_pushvfstring
[-0, +1, m]
const char *lua_pushvfstring (lua_State *L, const char *fmt, va_list argp);
Equivalent to lua_pushfstring
, except that it receives a va_list
instead of a variable number of arguments.
lua_rawequal
[-0, +0, -]
int lua_rawequal (lua_State *L, int index1, int index2);
Returns 1 if the two values in acceptable indices index1
and
index2
are primitively equal
(that is, without calling metamethods).
Otherwise returns 0.
Also returns 0 if any of the indices are non valid.
lua_rawget
[-1, +1, -]
void lua_rawget (lua_State *L, int index);
Similar to lua_gettable
, but does a raw access
(i.e., without metamethods).
lua_rawgeti
[-0, +1, -]
void lua_rawgeti (lua_State *L, int index, int n);
Pushes onto the stack the value t[n]
,
where t
is the value at the given valid index.
The access is raw;
that is, it does not invoke metamethods.
lua_rawset
[-2, +0, m]
void lua_rawset (lua_State *L, int index);
Similar to lua_settable
, but does a raw assignment
(i.e., without metamethods).
lua_rawseti
[-1, +0, m]
void lua_rawseti (lua_State *L, int index, int n);
Does the equivalent of t[n] = v
,
where t
is the value at the given valid index
and v
is the value at the top of the stack.
This function pops the value from the stack. The assignment is raw; that is, it does not invoke metamethods.
lua_Reader
typedef const char * (*lua_Reader) (lua_State *L, void *data, size_t *size);
The reader function used by lua_load
.
Every time it needs another piece of the chunk,
lua_load
calls the reader,
passing along its data
parameter.
The reader must return a pointer to a block of memory
with a new piece of the chunk
and set size
to the block size.
The block must exist until the reader function is called again.
To signal the end of the chunk,
the reader must return NULL
or set size
to zero.
The reader function may return pieces of any size greater than zero.
lua_register
[-0, +0, e]
void lua_register (lua_State *L, const char *name, lua_CFunction f);
Sets the C function f
as the new value of global name
.
It is defined as a macro:
#define lua_register(L,n,f) \ (lua_pushcfunction(L, f), lua_setglobal(L, n))
lua_remove
[-1, +0, -]
void lua_remove (lua_State *L, int index);
Removes the element at the given valid index, shifting down the elements above this index to fill the gap. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
lua_replace
[-1, +0, -]
void lua_replace (lua_State *L, int index);
Moves the top element into the given position (and pops it), without shifting any element (therefore replacing the value at the given position).
lua_resume
[-?, +?, -]
int lua_resume (lua_State *L, int narg);
Starts and resumes a coroutine in a given thread.
To start a coroutine, you first create a new thread
(see lua_newthread
);
then you push onto its stack the main function plus any arguments;
then you call lua_resume
,
with narg
being the number of arguments.
This call returns when the coroutine suspends or finishes its execution.
When it returns, the stack contains all values passed to lua_yield
,
or all values returned by the body function.
lua_resume
returns
LUA_YIELD
if the coroutine yields,
0 if the coroutine finishes its execution
without errors,
or an error code in case of errors (see lua_pcall
).
In case of errors,
the stack is not unwound,
so you can use the debug API over it.
The error message is on the top of the stack.
To restart a coroutine, you put on its stack only the values to
be passed as results from yield
,
and then call lua_resume
.
lua_setallocf
[-0, +0, -]
void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
Changes the allocator function of a given state to f
with user data ud
.
lua_setfenv
[-1, +0, -]
int lua_setfenv (lua_State *L, int index);
Pops a table from the stack and sets it as
the new environment for the value at the given index.
If the value at the given index is
neither a function nor a thread nor a userdata,
lua_setfenv
returns 0.
Otherwise it returns 1.
lua_setfield
[-1, +0, e]
void lua_setfield (lua_State *L, int index, const char *k);
Does the equivalent to t[k] = v
,
where t
is the value at the given valid index
and v
is the value at the top of the stack.
This function pops the value from the stack. As in Lua, this function may trigger a metamethod for the "newindex" event (see §2.8).
lua_setglobal
[-1, +0, e]
void lua_setglobal (lua_State *L, const char *name);
Pops a value from the stack and
sets it as the new value of global name
.
It is defined as a macro:
#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, s)
lua_setmetatable
[-1, +0, -]
int lua_setmetatable (lua_State *L, int index);
Pops a table from the stack and sets it as the new metatable for the value at the given acceptable index.
lua_settable
[-2, +0, e]
void lua_settable (lua_State *L, int index);
Does the equivalent to t[k] = v
,
where t
is the value at the given valid index,
v
is the value at the top of the stack,
and k
is the value just below the top.
This function pops both the key and the value from the stack. As in Lua, this function may trigger a metamethod for the "newindex" event (see §2.8).
lua_settop
[-?, +?, -]
void lua_settop (lua_State *L, int index);
Accepts any acceptable index, or 0,
and sets the stack top to this index.
If the new top is larger than the old one,
then the new elements are filled with nil.
If index
is 0, then all stack elements are removed.
lua_State
typedef struct lua_State lua_State;
Opaque structure that keeps the whole state of a Lua interpreter. The Lua library is fully reentrant: it has no global variables. All information about a state is kept in this structure.
A pointer to this state must be passed as the first argument to
every function in the library, except to lua_newstate
,
which creates a Lua state from scratch.
lua_status
[-0, +0, -]
int lua_status (lua_State *L);
Returns the status of the thread L
.
The status can be 0 for a normal thread,
an error code if the thread finished its execution with an error,
or LUA_YIELD
if the thread is suspended.
lua_toboolean
[-0, +0, -]
int lua_toboolean (lua_State *L, int index);
Converts the Lua value at the given acceptable index to a C boolean
value (0 or 1).
Like all tests in Lua,
lua_toboolean
returns 1 for any Lua value
different from false and nil;
otherwise it returns 0.
It also returns 0 when called with a non-valid index.
(If you want to accept only actual boolean values,
use lua_isboolean
to test the value's type.)
lua_tocfunction
[-0, +0, -]
lua_CFunction lua_tocfunction (lua_State *L, int index);
Converts a value at the given acceptable index to a C function.
That value must be a C function;
otherwise, returns NULL
.
lua_tointeger
[-0, +0, -]
lua_Integer lua_tointeger (lua_State *L, int index);
Converts the Lua value at the given acceptable index
to the signed integral type lua_Integer
.
The Lua value must be a number or a string convertible to a number
(see §2.2.1);
otherwise, lua_tointeger
returns 0.
If the number is not an integer, it is truncated in some non-specified way.
lua_tolstring
[-0, +0, m]
const char *lua_tolstring (lua_State *L, int index, size_t *len);
Converts the Lua value at the given acceptable index to a C string.
If len
is not NULL
,
it also sets *len
with the string length.
The Lua value must be a string or a number;
otherwise, the function returns NULL
.
If the value is a number,
then lua_tolstring
also
changes the actual value in the stack to a string.
(This change confuses lua_next
when lua_tolstring
is applied to keys during a table traversal.)
lua_tolstring
returns a fully aligned pointer
to a string inside the Lua state.
This string always has a zero ('\0
')
after its last character (as in C),
but can contain other zeros in its body.
Because Lua has garbage collection,
there is no guarantee that the pointer returned by lua_tolstring
will be valid after the corresponding value is removed from the stack.
lua_tonumber
[-0, +0, -]
lua_Number lua_tonumber (lua_State *L, int index);
Converts the Lua value at the given acceptable index
to the C type lua_Number
(see lua_Number
).
The Lua value must be a number or a string convertible to a number
(see §2.2.1);
otherwise, lua_tonumber
returns 0.
lua_topointer
[-0, +0, -]
const void *lua_topointer (lua_State *L, int index);
Converts the value at the given acceptable index to a generic
C pointer (void*
).
The value can be a userdata, a table, a thread, or a function;
otherwise, lua_topointer
returns NULL
.
Different objects will give different pointers.
There is no way to convert the pointer back to its original value.
Typically this function is used only for debug information.
lua_tostring
[-0, +0, m]
const char *lua_tostring (lua_State *L, int index);
Equivalent to lua_tolstring
with len
equal to NULL
.
lua_tothread
[-0, +0, -]
lua_State *lua_tothread (lua_State *L, int index);
Converts the value at the given acceptable index to a Lua thread
(represented as lua_State*
).
This value must be a thread;
otherwise, the function returns NULL
.
lua_touserdata
[-0, +0, -]
void *lua_touserdata (lua_State *L, int index);
If the value at the given acceptable index is a full userdata,
returns its block address.
If the value is a light userdata,
returns its pointer.
Otherwise, returns NULL
.
lua_type
[-0, +0, -]
int lua_type (lua_State *L, int index);
Returns the type of the value in the given acceptable index,
or LUA_TNONE
for a non-valid index
(that is, an index to an "empty" stack position).
The types returned by lua_type
are coded by the following constants
defined in lua.h
:
LUA_TNIL
,
LUA_TNUMBER
,
LUA_TBOOLEAN
,
LUA_TSTRING
,
LUA_TTABLE
,
LUA_TFUNCTION
,
LUA_TUSERDATA
,
LUA_TTHREAD
,
and
LUA_TLIGHTUSERDATA
.
lua_typename
[-0, +0, -]
const char *lua_typename (lua_State *L, int tp);
Returns the name of the type encoded by the value tp
,
which must be one the values returned by lua_type
.
lua_Writer
typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
The type of the writer function used by lua_dump
.
Every time it produces another piece of chunk,
lua_dump
calls the writer,
passing along the buffer to be written (p
),
its size (sz
),
and the data
parameter supplied to lua_dump
.
The writer returns an error code:
0 means no errors;
any other value means an error and stops lua_dump
from
calling the writer again.
lua_xmove
[-?, +?, -]
void lua_xmove (lua_State *from, lua_State *to, int n);
Exchange values between different threads of the same global state.
This function pops n
values from the stack from
,
and pushes them onto the stack to
.
lua_yield
[-?, +?, -]
int lua_yield (lua_State *L, int nresults);
Yields a coroutine.
This function should only be called as the return expression of a C function, as follows:
return lua_yield (L, nresults);
When a C function calls lua_yield
in that way,
the running coroutine suspends its execution,
and the call to lua_resume
that started this coroutine returns.
The parameter nresults
is the number of values from the stack
that are passed as results to lua_resume
.
Lua has no built-in debugging facilities. Instead, it offers a special interface by means of functions and hooks. This interface allows the construction of different kinds of debuggers, profilers, and other tools that need "inside information" from the interpreter.
lua_Debug
typedef struct lua_Debug { int event; const char *name; /* (n) */ const char *namewhat; /* (n) */ const char *what; /* (S) */ const char *source; /* (S) */ int currentline; /* (l) */ int nups; /* (u) number of upvalues */ int linedefined; /* (S) */ int lastlinedefined; /* (S) */ char short_src[LUA_IDSIZE]; /* (S) */ /* private part */ other fields } lua_Debug;
A structure used to carry different pieces of
information about an active function.
lua_getstack
fills only the private part
of this structure, for later use.
To fill the other fields of lua_Debug
with useful information,
call lua_getinfo
.
The fields of lua_Debug
have the following meaning:
source
:
If the function was defined in a string,
then source
is that string.
If the function was defined in a file,
then source
starts with a '@
' followed by the file name.
short_src
:
a "printable" version of source
, to be used in error messages.
linedefined
:
the line number where the definition of the function starts.
lastlinedefined
:
the line number where the definition of the function ends.
what
:
the string "Lua"
if the function is a Lua function,
"C"
if it is a C function,
"main"
if it is the main part of a chunk,
and "tail"
if it was a function that did a tail call.
In the latter case,
Lua has no other information about the function.
currentline
:
the current line where the given function is executing.
When no line information is available,
currentline
is set to -1.
name
:
a reasonable name for the given function.
Because functions in Lua are first-class values,
they do not have a fixed name:
some functions can be the value of multiple global variables,
while others can be stored only in a table field.
The lua_getinfo
function checks how the function was
called to find a suitable name.
If it cannot find a name,
then name
is set to NULL
.
namewhat
:
explains the name
field.
The value of namewhat
can be
"global"
, "local"
, "method"
,
"field"
, "upvalue"
, or ""
(the empty string),
according to how the function was called.
(Lua uses the empty string when no other option seems to apply.)
nups
:
the number of upvalues of the function.
lua_gethook
[-0, +0, -]
lua_Hook lua_gethook (lua_State *L);
Returns the current hook function.
lua_gethookcount
[-0, +0, -]
int lua_gethookcount (lua_State *L);
Returns the current hook count.
lua_gethookmask
[-0, +0, -]
int lua_gethookmask (lua_State *L);
Returns the current hook mask.
lua_getinfo
[-(0|1), +(0|1|2), m]
int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
Returns information about a specific function or function invocation.
To get information about a function invocation,
the parameter ar
must be a valid activation record that was
filled by a previous call to lua_getstack
or
given as argument to a hook (see lua_Hook
).
To get information about a function you push it onto the stack
and start the what
string with the character '>
'.
(In that case,
lua_getinfo
pops the function in the top of the stack.)
For instance, to know in which line a function f
was defined,
you can write the following code:
lua_Debug ar; lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* get global 'f' */ lua_getinfo(L, ">S", &ar); printf("%d\n", ar.linedefined);
Each character in the string what
selects some fields of the structure ar
to be filled or
a value to be pushed on the stack:
n
': fills in the field name
and namewhat
;
S
':
fills in the fields source
, short_src
,
linedefined
, lastlinedefined
, and what
;
l
': fills in the field currentline
;
u
': fills in the field nups
;
f
':
pushes onto the stack the function that is
running at the given level;
L
':
pushes onto the stack a table whose indices are the
numbers of the lines that are valid on the function.
(A valid line is a line with some associated code,
that is, a line where you can put a break point.
Non-valid lines include empty lines and comments.)
This function returns 0 on error
(for instance, an invalid option in what
).
lua_getlocal
[-0, +(0|1), -]
const char *lua_getlocal (lua_State *L, lua_Debug *ar, int n);
Gets information about a local variable of a given activation record.
The parameter ar
must be a valid activation record that was
filled by a previous call to lua_getstack
or
given as argument to a hook (see lua_Hook
).
The index n
selects which local variable to inspect
(1 is the first parameter or active local variable, and so on,
until the last active local variable).
lua_getlocal
pushes the variable's value onto the stack
and returns its name.
Variable names starting with '(
' (open parentheses)
represent internal variables
(loop control variables, temporaries, and C function locals).
Returns NULL
(and pushes nothing)
when the index is greater than
the number of active local variables.
lua_getstack
[-0, +0, -]
int lua_getstack (lua_State *L, int level, lua_Debug *ar);
Get information about the interpreter runtime stack.
This function fills parts of a lua_Debug
structure with
an identification of the activation record
of the function executing at a given level.
Level 0 is the current running function,
whereas level n+1 is the function that has called level n.
When there are no errors, lua_getstack
returns 1;
when called with a level greater than the stack depth,
it returns 0.
lua_getupvalue
[-0, +(0|1), -]
const char *lua_getupvalue (lua_State *L, int funcindex, int n);
Gets information about a closure's upvalue.
(For Lua functions,
upvalues are the external local variables that the function uses,
and that are consequently included in its closure.)
lua_getupvalue
gets the index n
of an upvalue,
pushes the upvalue's value onto the stack,
and returns its name.
funcindex
points to the closure in the stack.
(Upvalues have no particular order,
as they are active through the whole function.
So, they are numbered in an arbitrary order.)
Returns NULL
(and pushes nothing)
when the index is greater than the number of upvalues.
For C functions, this function uses the empty string ""
as a name for all upvalues.
lua_Hook
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
Type for debugging hook functions.
Whenever a hook is called, its ar
argument has its field
event
set to the specific event that triggered the hook.
Lua identifies these events with the following constants:
LUA_HOOKCALL
, LUA_HOOKRET
,
LUA_HOOKTAILRET
, LUA_HOOKLINE
,
and LUA_HOOKCOUNT
.
Moreover, for line events, the field currentline
is also set.
To get the value of any other field in ar
,
the hook must call lua_getinfo
.
For return events, event
can be LUA_HOOKRET
,
the normal value, or LUA_HOOKTAILRET
.
In the latter case, Lua is simulating a return from
a function that did a tail call;
in this case, it is useless to call lua_getinfo
.
While Lua is running a hook, it disables other calls to hooks. Therefore, if a hook calls back Lua to execute a function or a chunk, this execution occurs without any calls to hooks.
lua_sethook
[-0, +0, -]
int lua_sethook (lua_State *L, lua_Hook f, int mask, int count);
Sets the debugging hook function.
Argument f
is the hook function.
mask
specifies on which events the hook will be called:
it is formed by a bitwise or of the constants
LUA_MASKCALL
,
LUA_MASKRET
,
LUA_MASKLINE
,
and LUA_MASKCOUNT
.
The count
argument is only meaningful when the mask
includes LUA_MASKCOUNT
.
For each event, the hook is called as explained below: