lua-users home
lua-l archive

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


> On page 254 of the Blue PIL, there's a nice example of using 
> a fresh environment to share information among functions in a library.
> One thing I'm not clear on: whose responsibility is it to restore the
> previous environment?  The example doesn't show the environment
> being restored.  Is it somehow restored magically?  Does 'require'
> reset the environment when it's finished?  Or is the example wrong,
> and is it up to me to restore the environment in my own code?

It is never restored. What was changed was the environment of the
running function, luaopen_foo (in its Lua incarnation). This function
opens the library (which inherits its environment) and returns. It will
keep its changed environment for ever (which means until being collected
as garbage, after returning to 'require').

-- Roberto