lua-users home
lua-l archive

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



> "Frantisek Fuka" <fuka@fuxoft.cz> wrote:
>
> > module("MyModules.XML", package.seeall)
> what is the reason in using "module" with "seeall"? build the table
> yourself and throw away "module" ('cause this function is a bad idea
> anyway, imo %-). something like this:
>
> local mymod = {};
>
> function mymod.ABC ()
> ...
> end;
>
> ...
> ...
>
> return mymod;
>
> so you can have isolated namespace, access to globals and avoid global
> namespace polluting.

The namespace you created is not isolated. As soon as you return the local variable all bets are off on the "security" of anything you put in that table.

The use of the module() function is intended to provide official language support for modules. It is a very good idea to make use of it. If someone is using two modules in their code that both make use of your extremely large module, require() guarantees your module is loaded only once (saving time among other things). Some use require() to make sure certain base libraries are available, such as the string library (or module). This is good programming practice and shows your program's dependencies.

-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say."

-Will Durant