lua-users home
lua-l archive

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


On Wed, May 18, 2011 at 7:34 PM, Murray S. Kucherawy <msk@cloudmark.com> wrote:
> One thing I’m not certain about with that design: Will the garbage collector
> purge any global variables that exist in the state on completion of the
> pcall, or will they linger around for the next load-pcall on the same state
> object?  If the latter, can I use some getfenv/setfenv magic to reset things
> for the next iteration?  Or do I have to bite the bullet and do it the more
> expensive way?

>From the main thread (with no running functions):

lua_settop(L, 0);
lua_newtable(L);
lua_replace(L, LUA_REGISTRYINDEX);
lua_newtable(L);
lua_replace(L, LUA_GLOBALSINDEX);
lua_newtable(L);
lua_replace(L, LUA_ENVIRONINDEX);

This is an extreme example (clears everything in the state). How you
keep some data (i.e. library modules) persistent is an exercise for
the reader.

-- 
- Patrick Donnelly