[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Flushing global variables
- From: Tony Finch <dot@...>
- Date: Thu, 19 May 2011 10:48:43 +0100
Murray S. Kucherawy <msk@cloudmark.com> wrote:
> I'm working on an application that's multi-threaded, and to avoid a
> newstate-load-pcall-close series for every time I want to invoke a
> script, I'm thinking of allocating a pool of states and just pulling one
> out when it's time to run, which leaves me with just load-pcall every
> time.
Why not cache the parsed scripts, so it's just a pcall each time?
> 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?
Yes, it sounds like you want some kind of setfenv sandbox. You can use a
__index metatable entry on the temporary environment to pull in the
persistent global functions efficiently.
Tony.
--
f.anthony.n.finch <dot@dotat.at> http://dotat.at/
Rockall, Malin, Hebrides: South 5 to 7, occasionally gale 8 at first in
Rockall and Malin, veering west or northwest 4 or 5, then backing southwest 5
or 6 later. Rough or very rough. Occasional rain. Moderate or good,
occasionally poor.