lua-users home
lua-l archive

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


On Fri, Feb 22, 2013 at 10:29 AM, James Graves
<james.c.graves.jr@gmail.com> wrote:

> The goal is to isolate all the modules from each other and eliminate
> unintentional pollution of the global environment.  Every module has
> access to only just what it needs, no more and no less.
>
> James
>

That goal makes sense.

Could you please provide an example where this isn't already the case,
and make it one that does not involve the module writer returning
"_ENV" as the return value of their module?

If this is all about 5.2, then I don't see how there is a need to do
anything weird at all. If the module writer wants an isolated
environment, then they set _ENV to the local environment that you want
and if you want a common one, make a module that returns a table of
your desired environment and set the one that you are working on to
its return value.

This does not expose anything to any other module outside the one you
are targeting, provided that you do not return _ENV as the value.
Returning the normal table would not bring along anything in that
module's environment.

I think I'm missing something because I keep typing that and I keep
not seeing why there needs to be any additional metatable magic.