类似 Luabind-syntax(索引运算符)
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
是一个函数,它返回类型luabind::module_
,它有一个重载的[]
运算符,采用类型luabind::scope
的参数。 -
luabind::class_
是一个类,它有一个接受类型const char*
的构造函数和一个返回class_&
的成员函数def
,因此可以链接对def
的调用。 -
luabind::class_
是从一个名为luabind::detail::class_base
的类派生的,该类派生自luabind::scope
,因此返回的最终class_
可以转换为scope
并作为参数传递给luabind::module_::operator[]
。
相关文章:
- 重载元组索引运算符-C++
- 重载运算符 [] 用于从对象数组中给出特定索引
- 为什么函数的任何索引处的下标运算符在C++中总是返回1
- std::map 索引运算符与插入方法的性能
- 为什么我不能使用在 Visual C++ 32 位中实现运算符无符号 int() 作为数组索引的类?
- 在对象上运行,运算符重载 () 与索引
- 为什么在C 中使用索引运算符被认为是不好的样式
- <T> 在使用运算符+ 连接两个向量之前从类型向量中删除索引
- 当c 中的矢量容器过载[]运算符时,我对未定义的索引返回什么
- String_view的索引运算符([])之间的差异
- 为什么在 std::vector 中使用索引超出范围的运算符 [] 时没有出现异常?
- C++将索引器运算符添加到现有类而不进行修改
- 通过赋值运算符在索引处插入std::向量
- C++数组运算符和 *(数组 + 索引)之间有什么区别(如果有)
- c++中线程安全索引运算符的正确方法
- 堆中的对象和重写索引运算符
- 索引运算符的 deques 和超出 deque 大小的问题
- 数组索引运算符重载.现在无法使用比较运算符
- 多次调用索引运算符的性能
- 是否可以使用运算符重载按索引分配用户定义的数组?-C++