Re: question on modules (newbie)
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: question on modules (newbie)
- From: Ryanne Thomas Dolan <rtdmr6@...>
- Date: 2006年2月23日 09:24:24 -0600
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/