lua-users home
lua-l archive

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

> What is different is _ENV, which is set to a table that points to the
> the previous global environment. In 5.1, there were just upvalues,
> locals and one _G table.
> So in 5.2, you wipe out everything in the _ENV table when you call
> module without "package.seeall".
> Later in the parent scope, the effect lingers. Since module isn't
> intended to be nested like this, you'd never see it in real code, as
> far as I know.
> As has been mentioned, "module" is deprecated because putting things
> into the global environment is thought to be a decision of the user
> and not the module author. Also, the way that "_ENV" works is
> extremely powerful and provides for many of the mechanisms that would
> otherwise need "package.seeall" and other such magic.
> - Andrew
> PS: (function print("hello") end )() is a good way to encapsulate
> something within a scope, but it ends up leading to a bunch of ";" and
> is more verbose than using "do ... end".
> do
>    print("hello")
> end
> To each their own. It just took me a while to figure out what you were
> up to, the way that it was written.
> PPS: My apologies for assuming that you were new to lua.
No big deal :)

I understand, interesting.
I am moving everything to 5.2 don't even have 5.1 on my system.
I have a number of modules and I know that in version 5.3, module will be 
removed. I am trying to get ready.

Module is deprecated on 5.2 which normally means, user beware, but 
compatibility is maintained. In this case the implementation has changed and 
maybe incompatible in very subtle ways. This will not cause me any grief but 
it is always good to know.

Thank you.


PS: I think the removal of module is justified but sadly will effect a large 
amount of code.