lua-users home
lua-l archive

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

Frantisek Fuka wrote:
>> As stated by Patrick Donnelly, your problem come from the different
>> module names. require("foo") will return what is in
>> package.loaded["foo"], while module("bar") will create your module in
>> package.loaded["bar"].
> Yes, I understand perfectly. However, according to the documentation
> for "require"
> (,  
> after calling require ("foo") while the "foo" file begins with
> "module(bar)", the value of package.loaded["foo"] ("foo", not "bar"!)
> should be set to true, which it isn't. It's nil!  

Here is what I get :
-- foo.lua
module("bar", package.seeall)
print("loading ".._NAME.." as "..(...))
-- test.lua --> the output
local tmp = require 'foo' --> loading bar as foo
print(tmp) --> true
print( --> true
print( --> table: 00336EC0

So if you don't get that your installation has a problem. Are you using
Lua 5.0 with compat-5.1 ?

> I quote from the documentation: "Once a loader is found, require
> calls the loader with a single argument, modname. If the loader
> returns any value, require assigns the returned value to
> package.loaded[modname].   
> If the loader returns no value and has not assigned any value to
> package.loaded[modname], then require assigns true to this entry. In
> any case, require returns the final value of
> package.loaded[modname]."   
> Because this doesn't mention that the "modname" value could change
> somewhere during this process, this clearly implies that the final
> returned value of require("foo") is always either the module itself
> or "true", without any further conditions and caveats. However, in my
> example, the returned value is nil.    

"modname" never changes in the process. However "name" in the "module"
documentation is not the same as "modname" in the require documentation.
In many cases these variables have the same value, but not in yours, and
when you read the documentation with that in mind everything seems
pretty clear to me (except that your installations seems to have a bug).

> Again, I have no problems with "why doesn't this work, what should I
> do?" I just think the documentation is unclear in what ramifications
> the usage of module name in "module" command has.  

The Lua manual has very little redundancy, but I think the answer to any
question is in there. You just have to take the right bits to compose