Page Contents
Namespacing
There are a few ideas for namespaces - some are listed below.
1.
function namespace(name)
return function(interior)
_G[name] = interior
end
end
namespace "foo" {
bar = function(msg) ... end
}
foo.bar("Hello");
2.
function namespace(name)
if( name and name ~= "" ) then
_G[name] = _G[name] or {}
setfenv(1, _G[name]);
else
setfenv(1, getfenv(0) );
end
end
namespace "foo"
function bar(msg) ... end
namespace ""
Comments:
- There should be some way to set metatables on the namespace table through the 'namespace' function. I'm not entirely sure how you'd achieve this, though. --AndrewSidwell