lua-users home
lua-l archive

Re: setfenv/getfenv

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


I asked this before, but, did you consider to use a *named* upvalue
for the environment. Something like
 in c = <expr> do ... end
where globals in the "..." part are looked up in the upvalue c. This
has the advantage that you can swap the environment of the entire
block at once:
 local setenv
 in c = <expr> do
 <some code>
 function setenv(x)
 c = x
 end
 end
Calling setenv with a new table will now swap the environment of all
functions that are created in the block.
Bye,
Wim

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