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

Functions

llua_assert () raise an error when the argument is an error.
llua_verbose (f) report whenever a Lua reference is freed
llua_setmetatable (o, mt) set the metatable of o
llua_push (o) push the reference on the stack.
llua_push_object (L, value) push an llib object.

Properties

llua_is_lua_object (o) is this a Lua reference?
llua_getmetatable (o) get the metatable of o
llua_typename (o) type name of the reference.
llua_len (o) length of Lua reference, if a table or userdata.
llua_tostring (o) this returns the original raw C string.
llua_tonumber (o) the Lua reference as a number.
llua_gettable (o) can we get a field of this object?
llua_settable (o) can we set a field of this object?
llua_callable (o) can we call this object?

Creating

llua_new (L, idx) new Lua reference to value on stack.
llua_global (L) get the global state as a reference.
llua_newtable (L) a reference to a new Lua table.
llua_cfunction (L, f) a reference to a C function.

Converting

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.

LoadingAndEvaluating

llua_load (L, code, name) load a code string and return the compiled chunk as a reference.
llua_loadfile (L, filename) load a file and return the compiled chunk as a reference.
llua_eval (L, expr, fret) load and evaluate an expression.
llua_evalfile (L, file, fret, env) load and evaluate a file in an environment env may be NULL.

Calling

llua_callf (o, fmt, ...) call the reference, passing a number of arguments.
llua_call_or_die () call a function, raising an error.

GettingAndSetting

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:

  • f FILE *
llua_setmetatable (o, mt)
set the metatable of o

Parameters:

  • o llua_t *
  • mt llua_t *
llua_push (o)
push the reference on the stack.

Parameters:

  • o llua_t *

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:

  • o llua_t *

Returns:

    bool
llua_getmetatable (o)
get the metatable of o

Parameters:

  • o llua_t *

Returns:

    llua_t *
llua_typename (o)
type name of the reference.

Parameters:

  • o llua_t *

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:

  • o llua_t *

Returns:

    int
llua_tostring (o)
this returns the original raw C string.

Parameters:

  • o llua_t *

Returns:

    const char *
llua_tonumber (o)
the Lua reference as a number.

Parameters:

  • o llua_t *

Returns:

    lua_Number
llua_gettable (o)
can we get a field of this object?

Parameters:

  • o llua_t *

Returns:

    bool
llua_settable (o)
can we set a field of this object?

Parameters:

  • o llua_t *

Returns:

    bool
llua_callable (o)
can we call this object?

Parameters:

  • o llua_t *

Returns:

    bool

Creating

llua_new (L, idx)
new Lua reference to value on stack.

Parameters:

  • L lua_State *
  • idx int

Returns:

    llua_t *
llua_global (L)
get the global state as a reference.

Parameters:

  • L lua_State *

Returns:

    llua_t *
llua_newtable (L)
a reference to a new Lua table.

Parameters:

  • L lua_State *

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:

  • L lua_State *
  • idx int

Returns:

    void *
llua_to_obj_pop (L, idx)
convenient way to call llua_to_obj which pops the stack.

Parameters:

  • L lua_State *
  • idx int

Returns:

    void *
llua_tonumarray (L, idx)
Lua table as an array of doubles.

Parameters:

  • L lua_State *
  • idx int

Returns:

    double *
llua_tointarray (L, idx)
Lua table as an array of ints.

Parameters:

  • L lua_State *
  • idx int

Returns:

    int *
llua_tostrarray (L, idx)
Lua table as an array of strings.

Parameters:

  • L lua_State *
  • idx int

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:

  • o llua_t *
  • key int

Returns:

    void *
llua_rawgeti (o, key)
raw indexing with an integer key.

Parameters:

  • o llua_t *
  • key int

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
generated by LDoc 1.4.2