const std::string vec2 = "Vector2"; r = engine->RegisterObjectType( vec2.c_str(), sizeof(Vector2), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CA); assert( r >= 0 ); /* members */ r = engine->RegisterObjectProperty( vec2.c_str(), "float x", offsetof(Vector2, x)); assert( r >= 0 ); r = engine->RegisterObjectProperty( vec2.c_str(), "float y", offsetof(Vector2, y)); assert( r >= 0 ); /* constructors */ r = engine->RegisterObjectBehaviour( vec2.c_str(), asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(Vector2DefaultConstructor), asCALL_CDECL_OBJLAST); assert( r >= 0 ); r = engine->RegisterObjectBehaviour( vec2.c_str(), asBEHAVE_CONSTRUCT, "void f(const Vector2 &in)", asFUNCTION(Vector2CopyConstructor), asCALL_CDECL_OBJLAST); assert( r >= 0 ); r = engine->RegisterObjectBehaviour( vec2.c_str(), asBEHAVE_CONSTRUCT, "void f(float, float)", asFUNCTION(Vector2InitConstructor), asCALL_CDECL_OBJLAST); assert( r >= 0 ); /* operator overloads */ r = engine->RegisterObjectMethod( vec2.c_str(), "bool opEquals(const Vector2 &in) const", asMETHODPR(Vector2, operator ==, (const Vector2&) const, bool), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "bool opEquals(const Vector2 &in) const", asMETHODPR(Vector2, operator !=, (const Vector2&) const, bool), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "bool opCmp(const Vector2 &in) const", asMETHODPR(Vector2, operator >, (const Vector2&) const, bool), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "bool opCmp(const Vector2 &in) const", asMETHODPR(Vector2, operator <, (const Vector2&) const, bool), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "bool opCmp(const Vector2 &in) const", asMETHODPR(Vector2, operator >=, (const Vector2&) const, bool), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "bool opCmp(const Vector2 &in) const", asMETHODPR(Vector2, operator <=, (const Vector2&) const, bool), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 &opAddAssign(const Vector2 &in)", asMETHODPR(Vector2, operator +=, (const Vector2&), Vector2&), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 &opSubAssign(const Vector2 &in)", asMETHODPR(Vector2, operator -=, (const Vector2&), Vector2&), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 &opMulAssign(const Vector2 &in)", asMETHODPR(Vector2, operator *=, (const Vector2&), Vector2&), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 &opDivAssign(const Vector2 &in)", asMETHODPR(Vector2, operator /=, (const Vector2&), Vector2&), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 &opAddAssign(float)", asMETHODPR(Vector2, operator +=, (float), Vector2&), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 &opSubAssign(float)", asMETHODPR(Vector2, operator -=, (float), Vector2&), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 &opMulAssign(float)", asMETHODPR(Vector2, operator *=, (float), Vector2&), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 &opDivAssign(float)", asMETHODPR(Vector2, operator /=, (float), Vector2&), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 opAdd(const Vector2 &in) const", asMETHODPR(Vector2, operator +, (const Vector2&) const, Vector2), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 opSub(const Vector2 &in) const", asMETHODPR(Vector2, operator -, (const Vector2&) const, Vector2), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 opMul(const Vector2 &in) const", asMETHODPR(Vector2, operator *, (const Vector2&) const, Vector2), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 opDiv(const Vector2 &in) const", asMETHODPR(Vector2, operator /, (const Vector2&) const, Vector2), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 opAdd(float) const", asMETHODPR(Vector2, operator +, (float) const, Vector2), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 opSub(float) const", asMETHODPR(Vector2, operator -, (float) const, Vector2), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 opMul(float) const", asMETHODPR(Vector2, operator *, (float) const, Vector2), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 opDiv(float) const", asMETHODPR(Vector2, operator /, (float) const, Vector2), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 opAdd(float, const Vector2 &in) const", asFUNCTIONPR(operator +, (float, const Vector2&), Vector2), asCALL_CDECL_OBJLAST); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 opSub(float, const Vector2 &in) const", asFUNCTIONPR(operator -, (float, const Vector2&), Vector2), asCALL_CDECL_OBJLAST); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 opMul(float, const Vector2 &in) const", asFUNCTIONPR(operator *, (float, const Vector2&), Vector2), asCALL_CDECL_OBJLAST); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 opDiv(float, const Vector2 &in) const", asFUNCTIONPR(operator /, (float, const Vector2&), Vector2), asCALL_CDECL_OBJLAST); assert( r >= 0 ); // Register the object methods r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 normal() const", asMETHODPR( Vector2, Normal, (void) const, Vector2), asCALL_THISCALL ); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "float length() const", asMETHODPR( Vector2, Length, (void) const, float), asCALL_THISCALL ); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "float length_squared() const", asMETHODPR( Vector2, LengthSquared, (void) const, float), asCALL_THISCALL ); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "float distance(const Vector2 &in) const", asMETHODPR( Vector2, Distance, (const Vector2 &v) const, float), asCALL_THISCALL ); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "float distance_squared(const Vector2 &in) const", asMETHODPR( Vector2, DistanceSquared, (const Vector2 &v) const, float), asCALL_THISCALL ); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "float dot(const Vector2 &in) const", asMETHODPR( Vector2, Dot, (const Vector2 &v) const, float), asCALL_THISCALL ); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "float cross(const Vector2 &in) const", asMETHODPR( Vector2, Cross, (const Vector2 &v) const, float), asCALL_THISCALL ); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 min(const Vector2 &in) const", asMETHODPR( Vector2, Min, (const Vector2&) const, Vector2), asCALL_THISCALL ); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 max(const Vector2 &in) const", asMETHODPR( Vector2, Max, (const Vector2&) const, Vector2), asCALL_THISCALL ); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 to_degrees() const", asMETHODPR( Vector2, ToDegrees, (void) const, Vector2), asCALL_THISCALL ); assert( r >= 0 ); r = engine->RegisterObjectMethod( vec2.c_str(), "Vector2 to_radians() const", asMETHODPR( Vector2, ToRadians, (void) const, Vector2), asCALL_THISCALL ); assert( r >= 0 );
Half of those have not been tested but you get the idea.