Re: Flushing global variables
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Flushing global variables
- From: Patrick Donnelly <batrick@...>
- Date: 2011年5月19日 17:51:12 -0400
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