[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: glua (was: Function lua_register)
- From: Enrico Colombini <erix@...>
- Date: Fri, 11 Jan 2002 18:45:46 +0100
>you might want to take a look at tolua
>(http://www.tecgraf.puc-rio.br/~celes/tolua/)
>or one of the other code wrappers on the page http://www.lua.org/addons.html
By the way... after using tolua for a while, I decided that I needed
something simpler but more suited to low-level hand-crafted code (e.g.
functions accepting a variable number of arguments), so I wrote yet another
"code wrapper".
It is called "glua" (Lua-C glue), it is minimalist but very efficient and
it has error checking and meaningful error messages like tolua (usertypes
included). A typical C definition looks like this:
/*----- A minimal function: compute a bitwise AND -----*/
/* Lua: c = Bitand(a, b) [a,b,c: integers] */
glua_function(Bitand)
int a = glua_getInteger(1); /* get arg #1 */
int b = glua_getInteger(2); /* get arg #2 */
glua_getNone(3); /* error if extra args */
glua_pushNumber(a & b); /* compute and return 1 numeric result */
return 1;
}
(the missing open brace is intentional -- macros at work)
and, later in the file:
/*----- List of functions visible from Lua -----*/
static glua_fitem flist[] = {
glua_fn(Bitand)
/* ... */
};
/*----- Initialization -----*/
void gluatest_open (lua_State* lua)
{
glua_regFunctions(flist); /* functions */
/* numeric constants can be defined too */
/* usertags are defined and registered here */
}
I wrote glua a few months ago to interface with low-level graphics, than I
had a work overload and never got around to write a documentation.
If somebody is interested, I can try to find time to make that last step.
Enrico