[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: module loading in C
- From: Hans van der Meer <H.vanderMeer@...>
- Date: Tue, 2 Sep 2008 22:46:50 +0200
I am wrestling with keeping modules from crashing(disappearing?).
I have module A loaded from a lua program wth require, while
submodules A1, A2, .. are loaded by A on demand. The code for the
submodule loading:
lua_getglobal(L, subsystem); /* char *subsystem */
if (lua_isnil(L, -1)) {
lua_pop(L, 1); /* pop the nil */
lua_getglobal(L, "require"); /* setup call to require */
lua_pushstring(L, subsystem); /* argument is name of module to
load */
if (lua_pcall(L, 1, 1, 0)) luaL_error(L, "require failed");
}
If I have in the Lua program a statement:
subsys = require "A1"
before the programmatic loading will occur all is well, leave it out
and the program may crash when trying to enter a function in the
submodule A1. This occurs in the endgame of the program execution.
This follows from the fact that putting an offending operation within
a local do-end block has the garbage collector kick in at an earlier
moment.
I tried to fixate the module by putting the table returned by the
pcall to require in either LUA_ENVIRONINDEX or LUA_GLOBALSINDEX but
neither does work.
Clearly I am missing an essential point. But what?
I hope someone can point me in the right direction.
Hans van der Meer