lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

> 3) Take the above Lua code, and translate it into the equivalent C API
> functions. I dont know how I would move a table though in C ?
> None of the above sound very easy or pleasant,  however I am probably
> missing the obvious and elegant way to achieve this ?
> Any advice or code examples would be welcomed please. Thanks

Best way would be for your system to include a lua program text file,
which it runs at startup using luaL_dofile().

Its pretty common for bindings to have a core of C code, and then a
layer on top implemented in lua that makes the whole thing a little
easier to use.

I suspect that you'll find there is more and more simple setup and
arrangement tasks and convenience functions you'll want to layer on
top of your C bindings, or in this example, rearrangement of the C
bindings into new namespaces. Writing this stuff in lua is the easy

If you don't have a filesystem, or its otherwise difficult to arrange
this (I think you said you're on an embedded system of some sort),
then build the startup code lua into your system as a string, and do a
luaL_dostring() on it.

If you have to do it in C, doing what Luiz suggested is fairly easy,
you'd use a combinatin of lua_newtable(), lua_getglobal(),
lua_setglobal(), and lua_setfield() in order to get the graphics
global that swig created, and put it as a field called graphics inside
a new table you make, which you then assign to the global "acme". Then
assign nil to the global graphics.