[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: require "module" "feature" - syntax
- From: Tomas <tomas@...>
- Date: Wed, 11 Oct 2006 10:43:20 -0300 (BRT)
Hi Asko
There's been discussion about initializing only certain parts of a module, or
initializing it in a certain way.
I just came to try whether the title syntax would work, and it does!
require "module""feature"
require "module"{ "feature1", "feature7" }
Has anyone used this already (is this old stuff?) and is there any downsides
to it? The idea would be for 'require' to attach a '__call' metamethod to
the table it returns, which would in turn handle string and table-of-strings
to initialize certain parts of the system.
I think `require' returns everything the module returns or
what is defined in package.loaded[module_name]. If the module calls
`module' and does not return anything explicitly, then the result will
be `require' returning the new table/environment defined by `module'.
That said, you could achieve the desired behavior by simply
returning the function you mentioned. Something like:
module"my_mod"
...
return function (list)
if type(list) == "string" then
return _M[list]
elseif type(list) == "table" then
...
end
end
I think it should not be dificult to build a generic function
which could be used simply by any module:
return features
Regards,
Tomas