lua-users home
lua-l archive

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


Alex Queiroz wrote:
Hallo,

On 4/24/06, Chris Marrin <chris@marrin.com> wrote:

Module used like this:

    module "foo"
    function bar() ... end

I can put the above into a file called foo.lua and the require function
will load it. But if I did only this, calling foo.bar() as above would
fail, because local foo would be nil, because I did not return anything
from the implementation. In order to get foo.lua to work I would have to
do this:

    local package = package
    module "foo"
    function bar() ... end
    return package.loaded.foo



     No. All globals declared in the module will be put in the module
table, which will be returned by require().

But experience shows that, after you call 'module' there will be a global variable (_G.foo in this case). If you look at ll_module() you will see that it does indeed add this global variable.

--
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"'