lua-users home
lua-l archive

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


> > 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'
> 
> Can you list the exactly contents of your Feature1.lua file? I'm not sure
> I'm fully understanding your problem, but it  may be just a question of
> line reordering. See below.

The entire contents of the Feature1.lua is

	module "Tests.Component1"

The problem I'm experiencing is that it is possible to either prevent a
library from loading or loading it into unexpected tables by declaring global
variables. See below.

> 
> > 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".
> 
> That's the part that lost me. Since you have "Component1" both as a Lua
> file (part of the Test package) and a directory (where Feature1.lua is
> located) I'm not sure what module hierachy you want.
> 
> Do you want to have both the A.B.C namespace and a global (declared in
> A/B.lua) called C? If that is the case then you can try defining C before
> the definition of namespace A.B.C, as in (not tested)
> 
> ./A/B.lua
> -----------
> C = function() end -- this is C, global
> 
> module "A.B.C" -- from this line forward every "global" ends in the A.B.C
> namespace
> 
> function D() -- this is A.B.C.D
>   C() -- calls the global defined before the module definition
> end
> ----------
> 
> Would that work for you? Maybe I'm completely off mark here...
> 

This would work, but I do not have control over C = function()... . C is not
a function that the package needs. It is just a "global" function that the
user created before requiring the package. The presence of the function
causes the name conflict.

I'll try to explain my setup:

I want tables (containing namespaces) as follows:

	Tests
	Tests.Component1 -- Contains all the tests for Component1

These namespaces are created by 3 files:

	./Tests.lua - Loads all the components
	./Tests/Component1.lua - Loads all the features of component 1
	./Tests/Component1/Feature1.lua - Loads the tests for Feature1

The location of the files is necessitated by the conversion of package name
to file name in the require statements. The contents of the Tests.lua and
Component1.lua files are just require statements to load the sub packages,
thus:

./Test.lua contains

	module "Tests"
	require 'Tests.Component1'

./Tests/Component1.lua contains

	require 'Tests.Component1.Feature1'

./Tests/Component1/Feature1.lua must make its contents available in the
Component1 namespace, thus:

	module "Tests.Component1"
	... some more code to implement tests for feature 1.

When there exists a global variable with the name "Component1", the loading
of the tests will fail if the variable does not reference a table. I don't
know beforehand which global variables will exist. I can probably restructure
this to make it work, but that will not make the issue go away.

To summarise: It is possible to either prevent a library from loading or
loading it into unexpected tables by declaring global variables with this
implementation of compat.

Is this the intended behaviour?

Jarno