[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Multiple functions: was the gc
- From: William Ahern <wahern@...>
- Date: Tue, 22 Aug 2006 10:00:53 -0700
<snip>On Tue, 2006-08-22 at 08:48 +0100, David Jones wrote:
> If the function you want to execute _is_ the entire script loaded by
> lua_load then you can't do what you want. You must use lua_load to
> get a fresh instance of the function (this is a small drawback in Lua
> I think).
>
> However, I think wrapping your scripts should work:
> return function(...)
> -- original script goes here
> end
>
> Then, you can lua_load the script once and lua_call it each time you
> want a fresh function instance. That'll be dead fast.
That didn't work for me. The closure inherited the environment of the
outer function. You could do:
local fn = function() bar() end
setfenv(fn, foo)
return fn
But that only works for a single level. Any functions _called_ by that
closure are still bound to the original environment. In this case,
calling "bar" puts you right back where you started.
--
William Ahern <wahern@barracudanetworks.com>
--------------------------------------------------
This message was scanned for Spam, Spyware and Viruses
For more information, please visit:
http://www.barracudanetworks.com