lua-users home
lua-l archive

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


More detail required, but,

My bet is that you have a modified Global thread environment. If you
have called require() beforehand it is loaded into the master global environment
and the _G.package table. When calling your function, are these two references
being created in "your" LUA_GLOBALSINDEX or the master one?

DB

On Wed, Sep 3, 2008 at 6:46 AM, Hans van der Meer <H.vanderMeer@uva.nl> wrote:
> 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
>
>
>
>
>



-- 
David Burgess