lua-users home
lua-l archive

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


> > I'll try to explain my setup:
> >
> > I want tables (containing namespaces) as follows:
> >
> > 	Tests
> > 	Tests.Component1 -- Contains all the tests for Component1
> 
> May I suggest a different setup?
> 
> What about
> 
> /Tests
>   /Component1
>     Feature1.lua
> 
> and then use only
> 
> require "Tests.Component1.Feature1"
> 
> whenever you need to test feature1 from component1. The file could be only
> 
> module "Tests.Component1"
> ... some more code to implement tests for feature 1.
> 
> Notice that you can have more than one FeatureN file using the same module
> namespace (although local functions won't be visible among the different
> files).
> 
This could work. How would I provide my users with the ability to load all
the tests for component1? How would they load the tests for all the
components? (BTW: I think there was a discussion on this somewhere else)

> > 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.
> 
> I have to insist that apparently that is not the issue here, using the
> above namespace scheme should make things easier for you and your users,
> no?
> 
I've managed to reduce all of this into 1 file that demonstrates the issue.
Put all of this into ./Tests.lua. One could also distribute it over the files
as indicated by the comments

module "Tests"
--require 'Tests.Component1'

-- In ./Tests/Component1.lua
--require "Tests.Component1.Feature1"

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

Start Lua and assign something to the global variable Component1. Now require
'Tests' e.g.

- Component1 = function() end
- require 'Tests'

The response I see is (Lua 5.0.2, compat-5.1r2):
compat-5.1.lua:122: name conflict for module `Tests.Component1'
stack traceback:
        [C]: in function `error'
        compat-5.1.lua:122: in function `module'
        Tests.lua:8: in function `f'
        compat-5.1.lua:79: in function `require'
        stdin:1: in main chunk
        [C]: ?

By making the change to getfield(), this will work.
 
Jarno