[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Conceptual problem with module
- From: Chris Marrin <chris@...>
- Date: Tue, 25 Apr 2006 10:41:18 -0700
Mike Pall wrote:
Hi,
Chris Marrin wrote:
Why do modules get put into the global namespace? And why doesn't module
return a reference? Am I missing an easier way here?
Well, then why bother using it? You are better off with:
local _M = {}
local function helper() ... end -- not part of the module API
function _M.foo() ... end
function _M.bar() ... end
return _M
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? 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?
--
chris marrin ,""$,
chris@marrin.com b` $ ,,.
mP b' , 1$'
,.` ,b` ,` :$$'
,|` mP ,` ,mm
,b" b" ,` ,mm m$$ ,m ,`P$$
m$` ,b` .` ,mm ,'|$P ,|"1$` ,b$P ,` :$1
b$` ,$: :,`` |$$ ,` $$` ,|` ,$$,,`"$$ .` :$|
b$| _m$`,:` :$1 ,` ,$Pm|` ` :$$,..;"' |$:
P$b, _;b$$b$1" |$$ ,` ,$$" ``' $$
```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'