lua-users home
lua-l archive

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

Hi list,

I'm writing a binary module, and I'd like it to integrate gracefully
into the module system. So I tried to call the "module" Lua function
from my luaopen_module C function. I used the code below. I first call
"module" with the module name and package.seeall as parameters, and
then I put my functions in LUA_ENVIRONINDEX (which module is supposed
to have replaced with the module table).

Unfortunately, it doesn't seem to work. After loading the module, is nil. So is "module" supposed to work for C modules, and
if so how can I use it ?

static const struct luaL_reg module_functions[] = {
	{"new", lua__new},

MODULE_API int luaopen_module(lua_State *L)
   const struct luaL_reg* function = 0;

   lua_getglobal(L, "module");
   lua_pushvalue(L, 1);
   lua_getglobal(L, "package");
   lua_getfield(L, -1, "seeall");
   lua_insert(L, -2);
   lua_pop(L, 1);
   lua_call(L, 2, 0);

   function = module_functions;
   while (function->name)
       lua_pushcfunction(L, function->func);
       lua_setfield(L, LUA_ENVIRONINDEX, function->name);

   return 0;