lua-users home
lua-l archive

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


On Mon, 24 Apr 2006 15:44:08 -0700 Chris Marrin wrote:
> 
> I really like require and module as they exist in 5.1 ... almost.
> 
> The trouble I have is the fact that the module function adds the
> module name to the global table. That pollutes the namespace, which
> really bothers me. What I want to do is this:

Hi.

My solution:

--------------- the module file

-- ... contains the module name. We can change the filename, if we
-- use ... the module name will be updated.
package.loaded[...] = {} -- create the module table
module((...), package.seeall)

-- your code here

--------------- end of the module file

In fact the module function look for the table in package.loaded. If it
exists, it doesn't create it (and doesn't create the global table)

The manual doesn't says that module create a global table, but it does.
This is my little workaround.

In fact, I think it is better to do:
	package.loaded[...] =
		type(package.loaded[...])~="nil" and
			package.loaded[...]
		or {}


Mildred
-- 
Mildred       <xmpp:mildred@jabber.fr> <http://mildred632.free.fr/>
Clef GPG :    <hkp://pgp.mit.edu> ou <http://mildred632.free.fr/gpg_key>
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]