Member variables, properties, and functions

Adding variables, properties, and functions to a class in Lua Bridge is done in the same fashion as adding any of these things to a namespace. The functions are addDataaddFunctionand addProperty. None of these functions require any template data, but the data they point to does have to be scoped to the class it belongs to. The following code sample shows how to use these methods:

class Vec3 {
public:
float x, y, z;

float Magnitude() const;
void Normalize();
}

getGlobalNamespace(L)
.beginNamespace("Math")
.beginClass<Vec3>("Vec3")
.addData("x", &Vec3::x)
.addData("y", &Vec3::y)
.addData("z", &Vec3::z)
.addProperty("Magnitude", &Vec3::Magnitude)
.addFunction("Normalize", &Vec3::Normalize)
.endClass()
.endNameSpace();
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.152.136