lua-users home
lua-l archive

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


Greetings,

Within the same Lua environment, is it possible to dynamically load and unload chunks?

My application consists of dynamic objects, where each object can be associated with zero or more Lua scripts. For the most part, these scripts will be implemented as coroutines driven by object events for the life-cycle of the object itself.

I'm trying to determine whether I need a Lua environment for each object to run its scripts within, or whether I can get away with a single shared Lua environment.

What I've noticed so far is that if I load multiple scripts into the same Lua environment, I need to invoke lua_pcall() with an empty stack in order for things to get initialized so that script functions can be called with subsequent lua_pcall() invocations. This would seem to imply that once I make that first initialization call, I can't load any additional scripts into the Lua environment. Is this true?

Regards,
Brian Hassink

PS: The motivation for trying to do this in a single Lua environment is the possibility of easily sharing data between scripts (via globals), as well as eliminating the overhead of multiple Lua environments.