Jump to content
  • Advertisement
Sign in to follow this  

Registering global opEquals

This topic is 1437 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:


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?



Share this post

Link to post
Share on other sites
A pointer and a reference in C++ are identical with regards to the ABI.

The only difference is at a higher level where the reference has the restriction that it is not expected to be null, neither can it be reassigned. But for the calling convention this has no importance.

You are correct in registering this function using RegisterObjectMethod and the asCALL_CDECL_OBJLAST calling convention.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!