类似 Luabind 的语法(索引运算符)
Luabind-like syntax (index operator)
目前我正在试验 Luabind-Library,我偶然发现了它的调用语法。它的行为和工作方式与预期的一样,但不知何故我无法理解它为什么或如何工作。
有问题的代码如下:
Class Animation
{
std::vector frames;
public:
Animation(){}
~Animation(){}
addFrame(const Texture2D *in_image);
};
//Somewhere else
luabind::module(LuaState)
[
luabind::class_("Animation") // < "Animation" how we want to name the Class in the Lua runtime
.def(luabind::constructor<>()) // < Binds the empty constructor
.def("addFrame", &Animation::addFrame) // < Binds the &Animation::addFrame method to lua with the name "addFrame"
];
说得更具体一点,我不明白方括号里是什么情况。为什么这行得通?我试图阅读 Luabind 的源代码,遗憾的是没有成功。我也尝试重建这种行为,但也没有成功。
那么,我是否遗漏了一些非常明显的东西?
提前致谢!
luabind::module
是一个函数,它 returns 类型 luabind::module_
,它有一个重载的 []
运算符接受类型 luabind::scope
的参数。
luabind::class_
是一个 class 并且它有一个采用类型 const char*
的构造函数和一个成员函数 def
其中 returns class_&
因此可以链接对 def
的调用。
luabind::class_
派生了一个叫luabind::detail::class_base
的class,派生自luabind::scope
,所以最后返回的class_
可以转化为scope
并作为参数传递给 luabind::module_::operator[]
.
目前我正在试验 Luabind-Library,我偶然发现了它的调用语法。它的行为和工作方式与预期的一样,但不知何故我无法理解它为什么或如何工作。
有问题的代码如下:
Class Animation
{
std::vector frames;
public:
Animation(){}
~Animation(){}
addFrame(const Texture2D *in_image);
};
//Somewhere else
luabind::module(LuaState)
[
luabind::class_("Animation") // < "Animation" how we want to name the Class in the Lua runtime
.def(luabind::constructor<>()) // < Binds the empty constructor
.def("addFrame", &Animation::addFrame) // < Binds the &Animation::addFrame method to lua with the name "addFrame"
];
说得更具体一点,我不明白方括号里是什么情况。为什么这行得通?我试图阅读 Luabind 的源代码,遗憾的是没有成功。我也尝试重建这种行为,但也没有成功。
那么,我是否遗漏了一些非常明显的东西?
提前致谢!
luabind::module
是一个函数,它 returns 类型luabind::module_
,它有一个重载的[]
运算符接受类型luabind::scope
的参数。luabind::class_
是一个 class 并且它有一个采用类型const char*
的构造函数和一个成员函数def
其中 returnsclass_&
因此可以链接对def
的调用。luabind::class_
派生了一个叫luabind::detail::class_base
的class,派生自luabind::scope
,所以最后返回的class_
可以转化为scope
并作为参数传递给luabind::module_::operator[]
.