[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Packaging and importing
- From: PA <petite.abeille@...>
- Date: Sat, 13 Aug 2005 18:58:52 +0200
On Aug 13, 2005, at 17:18, Chris Marrin wrote:
In other words, does the package get put into the global namespace or
not?
It depends.
In theory, they shouldn't. In practice, any package can stick whatever
it feels like in _G, itself included. Or highjack _G altogether. To
complicate matters further more, a package doesn't have to return
itself either.
For example, most of Luiz packages don't play well with 'require':
local md5 = require( "md5" )
print( type( md5 ), md5 )
> string md5
Instead of returning itself, the md5 package returns its name.
Diego favors modules which register themselves with _G no matter what.
But at least they return themselves as well:
local socket = require( "socket" )
print( type( socket ), socket )
> table table: 0x118480
In other words, anything goes :)
It would be nice though to have a consistent behavior, e.g. 'require'
always returning a table of functions, instead of the current
unpredictable situation...
On the other hand, well, it's not such a big issue in practice as you
are most likely in full control of your environment and can impose
whatever policy you see fit.
For example, LU never defines anything in _G and always returns its
functionalities as a table of functions:
-- import dependencies
local LUObject = require( "LUObject" )
-- define the class
local self = LUObject()
...
return self
http://dev.alt.textdrive.com/browser/lu/
Cheers
--
PA, Onnay Equitursay
http://alt.textdrive.com/