我在 C 中为 Lua 编写了许多模块。每个模块都包含一个 Lua 用户数据类型,我像这样加载和使用它们:
A = require("A")
B = require("B")
a = A.new(3,{1,2,3})
b1 = B.new(1)
b2 = B.new(2) * b1
现在我想将两种用户数据类型放在一个AandB
可以像这样使用的共享库中
AB = require("AandB")
AB.A.new(3,{1,2,3})
什么是实现这一目标的好方法?现在我的luaopen_*
功能看起来像这样
int luaopen_A(lua_State *L) {
luaL_newmetatable(L, A_MT);
luaL_setfuncs(L, A_methods, 0);
luaL_newlib(L, A_functions);
return 1;
};
并且是否有可能仍然只加载部分,例如:A = require("AandB.A")
?