lua-users home
lua-l archive

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


I think you guys are forgetting something.  The package.seeall modifier is required for the effect you are describing:

--in test.lua:
module "test";

function foo () print "hello world" end;

>require "test";
>test.foo ();
./test.lua:7: attempt to call global 'print' (a nil value)
stack traceback:
        ./test.lua:4: in function 'foo'
        stdin:1: in main chunk
        [C]: ?

The "test" module above will break because the print function is no longer defined within foo's environment.  To fix this, you need package.seeall:

--in test.lua
module ("test", package.seeall);

function foo () print "hello world" end;

The package.seeall modifier makes the module inherit its environment from the environment in which module is called.  Without this, using require before module is pointless.


On Thu, 2006-02-23 at 09:15 -0300, Alex Queiroz wrote:
Hallo,

On 2/23/06, Romulo Bahiense <romulo@icontroller.com.br> wrote:
> - module should be the first function to be called in the
> file/script/chunk, or will you have unexpected behavior.
>

     Is this really true? I usually do my require()'s before calling module().

--
-alex
http://www.ventonegro.org/