lua-users home
lua-l archive

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


I'm not quite sure if I'm using the package feature wisely but this is what I
have. I'm trying to load a package structure that looks like this:

	Tests
	Tests.Component1
	Tests.Component1.Feature1

In the root folder I have a file called Tests.lua to load the components.
Note the module keyword at the top:

	./Tests.lua
	module "Tests"
	require 'Tests.Component1'

The Tests folder has a file called Component1.lua. It loads the features.
Note
no module:

	./Tests/Component1.lua
	require 'Tests.Component1.Feature1'

The Feature1.lua file is in Tests/Component1 and is a module of the
Component1
package.

	./Tests/Component1/Feature1.lua
	module "Tests.Component1"

I create a global value called Component1 (it can be anything but a table)
e.g. Component1 = function() end

Then I try to require 'Tests'. I end up with

    compat-5.1.lua:122: name conflict for module `Tests.Component1'


The error is triggered from in ./Tests/Component1/Feature1.lua:1 in the
implementation of 'module "Tests.Component1"'. By the time this line is
executed, the Tests namespace has been created. (That happens in ./Tests.lua)
However, at this time the Tests namespace does not contain the Component1
namespace. (The Tests table is empty except for the _NAME, _PACKAGE and _M).
The Component1 namespace and table only gets created in Feature1.lua.
However, the lookup of the name "Component1"  in the Tests namespace produces
the global Component1 value. This causes the "name conflict".

This can be removed by changing 1 line in compat-5.1.lua. In the getfield
function change

    t = t[w]

to

    t = rawget( t, w )

Now the lookup for 'Component1' on the Tests table fails because the global
namespace is not searched. The Component1 namespace is now also created
properly.

I have not tested this with work6. Is this the intended behaviour? This
implies
that one can have a namespace A.B, but not have the B table an element of A.
B can be a "global".

Jarno van Rooyen