I have a C++ function that looks like this:
namespace MyNamespace
{
inline bool operator==(const MyVec3& a, const MyVec3& b)
{
return ...; // left out for brevity
}
}
MyVec3 is registered like this:
SetDefaultNamespace("MyNamespace");
RegisterObjectType("MyVec3", sizeof(MyNamespace::MyVec3), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CDAK | asOBJ_APP_CLASS_ALLFLOATS);
I initially tried registering a global opEquals like so:
RegisterGlobalFunction("bool opEquals(const MyVec3&in, const MyVec3&in)", asFUNCTIONPR(MyNamespace::operator==, (const MyNamespace::MyVec3&,const MyNamespace::MyVec3&), bool), asCALL_CDECL)
which compiled, but at runtime I wasn't able to compare two MyVec3 instances as a == b
Then I tried registering the C++ function like so:
RegisterObjectMethod("MyVec3", "bool opEquals(const MyVec3& in) const", asFUNCTIONPR(MyNamespace::operator==, (const MyNamespace::MyVec3&,const MyNamespace::MyVec3&), bool), asCALL_CDECL_OBJLAST)
which so far is working fine.. but I'm slightly concerned that a asCALL_CDECL_OBJLAST calling convention would expect the C++ function to take a MyVec3*, but in this case the actual function takes a const MyVec3&. Is it just happening to work because under the hood a reference and a pointer are the same thing?
What's your advice for registering this C++ function with AngelScript?
Thanks!