Module llua
llua provides a higher-level way to integrate Lua into C projects,
by defining reference objects and providing operations like calling,
accessing, etc on them.
Most explicit manipulation of the Lua
stack becomes unnecessary.
Info:
- Copyright: Steve Donovan,2014
- License: BSD
llua_to_obj (L, idx) |
value on stack as a llib object, or Lua reference. |
llua_to_obj_pop (L, idx) |
convenient way to call llua_to_obj which pops the stack. |
llua_tonumarray (L, idx) |
Lua table as an array of doubles. |
llua_tointarray (L, idx) |
Lua table as an array of ints. |
llua_tostrarray (L, idx) |
Lua table as an array of strings. |
llua_convert (L, kind, P, idx) |
Read a value on the stack into a variable. |
llua_pop_vars (L, fmt, ...) |
pop some values off the Lua stack. |
llua_gets (o, key) |
index the reference with a string key, returning an object. |
llua_gets_v (o, key, ...) |
index the reference with multiple string keys and type-specifiers. |
llua_geti (o, key) |
index the reference with an integer key. |
llua_rawgeti (o, key) |
raw indexing with an integer key. |
llua_seti (o, key, value) |
set value using integer key. |
llua_sets (o, key, value) |
set value using integer key. |
llua_sets_v (o, key, ...) |
set multiple keys and values on the reference. |
Functions
-
llua_assert ()
-
raise an error when the argument is an error.
-
llua_verbose (f)
-
report whenever a Lua reference is freed
Parameters:
-
llua_setmetatable (o, mt)
-
set the metatable of
o
Parameters:
-
llua_push (o)
-
push the reference on the stack.
Parameters:
Returns:
lua_State *
-
llua_push_object (L, value)
-
push an llib object.
equivalent to llua_push if it’s a llua ref, otherwise
uses llib type. If there’s no type it assumes a plain
string literal.
Parameters:
- L
lua_State *
- value
void *
Properties
-
llua_is_lua_object (o)
-
is this a Lua reference?
Parameters:
Returns:
bool
-
llua_getmetatable (o)
-
get the metatable of
o
Parameters:
Returns:
llua_t *
-
llua_typename (o)
-
type name of the reference.
Parameters:
Returns:
const char *
-
llua_len (o)
-
length of Lua reference, if a table or userdata.
Note that we are specifically not using
lua_rawlen
here!
Parameters:
Returns:
int
-
llua_tostring (o)
-
this returns the original raw C string.
Parameters:
Returns:
const char *
-
llua_tonumber (o)
-
the Lua reference as a number.
Parameters:
Returns:
lua_Number
-
llua_gettable (o)
-
can we get a field of this object?
Parameters:
Returns:
bool
-
llua_settable (o)
-
can we set a field of this object?
Parameters:
Returns:
bool
-
llua_callable (o)
-
can we call this object?
Parameters:
Returns:
bool
Creating
-
llua_new (L, idx)
-
new Lua reference to value on stack.
Parameters:
Returns:
llua_t *
-
llua_global (L)
-
get the global state as a reference.
Parameters:
Returns:
llua_t *
-
llua_newtable (L)
-
a reference to a new Lua table.
Parameters:
Returns:
llua_t *
-
llua_cfunction (L, f)
-
a reference to a C function.
Parameters:
- L
lua_State *
- f
lua_CFunction
Returns:
llua_t *
Converting
-
llua_to_obj (L, idx)
-
value on stack as a llib object, or Lua reference.
Result can be NULL, a string, a llib boxed value,
or a
llua_t
reference.
Parameters:
Returns:
void *
-
llua_to_obj_pop (L, idx)
-
convenient way to call llua_to_obj which pops the stack.
Parameters:
Returns:
void *
-
llua_tonumarray (L, idx)
-
Lua table as an array of doubles.
Parameters:
Returns:
double *
-
llua_tointarray (L, idx)
-
Lua table as an array of ints.
Parameters:
Returns:
int *
-
llua_tostrarray (L, idx)
-
Lua table as an array of strings.
Parameters:
Returns:
char * *
-
llua_convert (L, kind, P, idx)
-
Read a value on the stack into a variable.
kind
is a type specifier
- ‘i’ integer
- 'b' boolean
- 'f' double
- ’s' string
- 'o' object (as in llua_to_obj )
- ‘L’ llua reference
- 'I' array of integers
- 'F' array of doubles
- ’S' array of strings
Parameters:
- L
lua_State *
- kind
char
- P
void *
- idx
int
Returns:
err_t
-
llua_pop_vars (L, fmt, ...)
-
pop some values off the Lua stack.
Uses llua_convert
Parameters:
- L
lua_State *
- fmt
const char *
- ...
Returns:
err_t
LoadingAndEvaluating
-
llua_load (L, code, name)
-
load a code string and return the compiled chunk as a reference.
Parameters:
- L
lua_State *
- code
const char *
- name
const char *
Returns:
llua_t *
-
llua_loadfile (L, filename)
-
load a file and return the compiled chunk as a reference.
Parameters:
- L
lua_State *
- filename
const char *
Returns:
llua_t *
-
llua_eval (L, expr, fret)
-
load and evaluate an expression.
fret
is a type specifier for the result, like llua_callf .
Parameters:
- L
lua_State *
- expr
const char *
- fret
const char *
Returns:
void *
-
llua_evalfile (L, file, fret, env)
-
load and evaluate a file in an environment
env
may be NULL.
fret
is a type specifier for the result, like llua_callf .
Parameters:
- L
lua_State *
- file
const char *
- fret
const char *
- env
llua_t *
Returns:
void *
Calling
-
llua_callf (o, fmt, ...)
-
call the reference, passing a number of arguments.
These are specified by a set of type specifiers fmt
. Apart
from the usual ones, we have ‘m’ (which must be first) which
means “call the method by name” where o
must be an object,
‘v’ which means “push the value at the index”, and ‘x’ which
means “C function”.
May optionally capture multiple return values with llua_convert .
There are some common cases that have symbolic names:
L_NONE
call doesn’t return anything
L_VAL
we return a single value
L_REF
we always return result as a llua reference
L_ERR
Lua error convention, either or <error-string>
Parameters:
- o
llua_t *
- fmt
const char *
- ...
Returns:
void *
Usage:
llua_callf(strfind,"ss",str,";$","i",&i);
llua_callf(open,"s","test.txt",L_ERR)
llua_callf(file,"ms","write","hello there\n",L_NONE);
-
llua_call_or_die ()
-
call a function, raising an error.
A useful combination of llua_callf and llua_assert
GettingAndSetting
-
llua_gets (o, key)
-
index the reference with a string key, returning an object.
‘object’ defined as with llua_to_obj
Parameters:
- o
llua_t *
- key
const char *
Returns:
void *
-
llua_gets_v (o, key, ...)
-
index the reference with multiple string keys and type-specifiers.
Type specifiers are as with llua_convert
Parameters:
- o
llua_t *
- key
const char *
- ...
Returns:
err_t
Usage:
llua_gets_v(T,"key1","s",&str,NULL);
-
llua_geti (o, key)
-
index the reference with an integer key.
Parameters:
Returns:
void *
-
llua_rawgeti (o, key)
-
raw indexing with an integer key.
Parameters:
Returns:
void *
-
llua_seti (o, key, value)
-
set value using integer key.
uses llua_push_object
Parameters:
- o
llua_t *
- key
int
- value
void *
-
llua_sets (o, key, value)
-
set value using integer key.
uses llua_push_object
Parameters:
- o
llua_t *
- key
const char *
- value
void *
-
llua_sets_v (o, key, ...)
-
set multiple keys and values on the reference.
uses type specifiers like llua_callf
Parameters:
- o
llua_t *
- key
const char *
- ...
Returns:
err_t