lua-users home
lua-l archive

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


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.

Bye,
     Mike