lua-users home
lua-l archive

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


On Wed, Feb 3, 2010 at 9:48 PM, Fabio Mascarenhas <mascarenhas@acm.org> wrote:
> Hi,
> I can add a compile-time option to Rings to replace the current
> initialization (just a call to luaL_openlibs) with anything you want, so you
> could define a function like
> static void myapp_initializestate(lua_State *L) {
>   luaL_openlibs(L);
>   /* do stuff with loaders, preload etc. */
> }
> and then compile rings with -DRINGS_INITIALIZE=myapp_initializestate. What
> do you think?

Normally, I don't think this is required, tell user to compile lua
with a modified version of linit.c seems to be a better approach. i.e.
add extra init stuffs inside luaL_openlibs(L);

But your approach enables a different library for the slave state,
this is a feature, and user should be able to choose initialize
function on-the-fly.

You can have a api_function which takes a function pointer as
parameter, and let user to pass the function pointer. In this way, you
know you don't need user init function if user has not called your
api_function, and if user had provided a function pointer you call
user's init function.