Currently im experimenting with the Luabind-Library and I stumbled upon its calling syntax. It behaves and works like expected, but somehow I can not understand why or how it does.
The code in question is following:
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"
];
To be more specific, I don't understand what's happening in the square brackets. Why does this work? I tried to read trough the source code of Luabind, sadly without success. I also tried to reconstruct this behaviour, which was also unsuccessful.
So, am I missing something very obvious?
Thanks in advance!
luabind::moduleis a function, and it returns typeluabind::module_, which has an overloaded[]operator taking an argument of typeluabind::scope.luabind::class_is a class and it has a constructor that takes typeconst char*and a member functiondefwhich returnsclass_&so calls todefcan be chained.luabind::class_is derived from a class calledluabind::detail::class_base, which is derived fromluabind::scope, so the finalclass_returned can be converted toscopeand passed as an argument toluabind::module_::operator[].