lua-users home
lua-l archive

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

On Oct 19, 2011, at 9:08 PM, Philipp Janda wrote:

> What happens if the name passed to require and the name passed to module differ?

Then hopefully you know what you are doing... or you have a typo...

> Wouldn't require just return true

In case of name mismatch, require raises an exception...


local foo = require( 'baz' )

 module 'baz' not found

> and the actual module ends up somewhere hidden in package.loaded?

Modules are named. They will end up under their assigned name.

> It seems to me that the name parameter to module might be problematic if you don't set globals.

How so? This is not meant to prevent people from doing silly mistakes. Just to name their modules.

> Maybe you shouldn't unconditionally replace all non-table values from package.loaded in case some other module placed a function or a string there (which could happen if "require-name" and "module-name" differed).

Ah, yes... there is a sort of marker put in package.loaded by require to sort out circular dependencies during loading... I don't recall the details, but module circa 5.1 has all this sorted out... e.g.:

> The proposed module-function doesn't mess with globals anymore, but it does mess with package.loaded

Well... "mess" might not be the right term... it simply sets it... just as module 5.1 does... module & require work both in terms of package.loaded in tandem...

> and therefore should make sure that it does not disrupt other legitimate uses of package.loaded.