lua-users home
lua-l archive

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


Apologies in advance if the formatting of this e-mail is bad. I'm still looking for a fix (probably just going to switch e-mails)

> Yes, I understand perfectly. However, according to the documentation
> for "require" (http://www.lua.org/manual/5.1/manual.html#pdf-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!
>
> > Unless that's what you want (there are special cases where you might
> > want that seemingly odd behaviour)
>
> Yes, that's what I want. I want my module's name to be independent of
> its filename. It works exactly as I intended (it's some advance
> dynamic module loading/debugging stuff) and the only reason why I
> wrote my post is that documentation seems to be wrong because it
> implies that "require" always returns the pointer to the loaded
> module. The Lua Book even suggests that I can use the following
> command to keep the reference to the loaded module like this:

My tests show that require("modname") always assigns true to package.loaded.modname (using your naming conventions). I think you should provide more code for us to see why nil is assigned, as I can't find a case for it.

You should use a preloader for this, as it will do what you need quite well. If you do it your way currently you end up with a module in package.loaded ("xml") that really isn't a module (it just has the value of true).

function package.preload.xml()
  dofile("xml.lua");
  ...
  package.loaded.xml = package.loaded["MyModules.XML"];
  return package.loaded["MyModules.XML"];
end;

HTH,

-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say."

-Will Durant