Lua package containing subpackages
I wrote several modules for Lua in C. Each of them contains a Lua useridata datatype and I load and use them like this:
A = require("A")
B = require("B")
a = A.new(3,{1,2,3})
b1 = B.new(1)
b2 = B.new(2) * b1
Now I would like to put both types of user data into one shared library AandB
that can be used like
AB = require("AandB")
AB.A.new(3,{1,2,3})
What's a good way to achieve this? Right now my functions luaopen_*
look like this:
int luaopen_A(lua_State *L) {
luaL_newmetatable(L, A_MT);
luaL_setfuncs(L, A_methods, 0);
luaL_newlib(L, A_functions);
return 1;
};
And is it possible then to load only a part, for example. for example A = require("AandB.A")
:?
+3
source to share
2 answers