July 2018
Beginner
202 pages
5h 42m
English
Lua Bridge only supports a single constructor. Overloaded constructors are not possible to declare with Lua Bridge. A constructor can be added with the addConstructor function. The function signature of the constructor must be specified as a template argument, since a class may have multiple overloaded constructors. The following code shows a C++ class with three constructors, but only the one that takes three floats is exposed to Lua:
class Vec3 { public: Vec3(); Vec3(const Vec3& other); Vec3(float x, float y, float z);}getGlobalNamespace(L) .beginNamespace("Math") .beginClass<Vec3>("Vec3") .addConstructor<void (*) (float, float, float)>() .endClass() .endNamespace();