lua-users home
lua-l archive

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


2012/8/27 Jay Carlson <nop@nop.com>:
> The alternative is ml=require"ml", and we seem to be trying
> to discourage that.

Are we? Even in Lua 5.2, we still have "lua -i -l mymodule"
and hey presto, there's something in the global namespace called
"mymodule".

No, what we are trying to discourage is modules assigning things
directly to global names, instead of the user program doing it.
There's nothing evil about global variables.  What is evil, is code
that you can't see in front of your nose assigning stuff to them.

I absolutely agree with the title of your post, but I disagree with
the imputation that it's a weakness of the current require. I believe
the notion that module names should be local variables all the time is
misguided.  Sometimes maybe, for special reasons, such as sandboxing,
but not regularly.

Personally I never assign a module to a local variable.  The members
actually use out of the module, yes, not only for efficiency, but
because it's a PITA to type math.exp and table.sort and io.open all
the time.