lua-users home
lua-l archive

Re: using setfenv recursively

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


On 11/4/07, Matthew Armstrong <turkeypotpie@gmail.com> wrote:
> myFunc = protectedEnv(
> function()
> -- If I call myFunc inside here, my environments start colliding.
> end)
I think I may understand what your problem is now. If you call myFunc
inside your function, it's actually attempting to call the variable
myFunc. Remember that myFunc is a reference to your function. If you
make it point to a different function then your environments will
"collide" as you said. What you can do instead is define a local that
refers to your function like so:
do
 local x;
 x = function() ... x() ... end
 protectedEnv(x);
 myFunc = x;
end;
-- 
-Patrick Donnelly
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."
-Will Durant

AltStyle によって変換されたページ (->オリジナル) /