lua-users home
lua-l archive

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


Hi,

Chris Marrin wrote:
> Mike Pall wrote:
> >The lost convenience of using global assignment for module
> >function definitions shouldn't worry you. In fact now you have
> >unrestricted access to all globals (you'd need package.seeall for
> >module()). It also provides a clear indication which functions
> >are part of the module API.
> 
> But global assignment is just a convenience, it provides a sandbox for 
> the module, right?

Well, but who needs this (pseudo) sandbox? Personally I try to
avoid the use of global variables (wherever they end up). Module
scoped local variables have better isolation properties and are
faster.

> If you add a setfenv after the table creation, you 
> would get that, right? And if you did that, then you get the 
> "convenience" of global assignment. And you can still use 'local 
> function' for unexposed functions, couldn't you?

3 x Yes. But you loose access to the globals unless you cache a
reference to them before the setfenv or use an __index chain,
like package.seeall does.

Bye,
     Mike