Sign in to follow this  

Registering Operator Overloading with Angelscript

This topic is 2543 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

Hey Everyone! Thanks for reading.

I've been planning to do an angelscript implementation in my project for quite some time now. I've made a basic script engine implementation a while back, and only just came around to doing the actual bindings.

Now what confuses me is the Operator overloading. I've found some results on this forum of possibilities to actually register the operators using asBEHAVE_ADD and such, and I remember seeing something like this in the documentation a LONG time ago.

However now it seems defines like asBEHAVE_ADD no longer exist, and the manual states I should add functions like opopAdd and opAssign to my class, or make other wrapper functions for them and register those!

Is this really the only option now? 'cause being able to register the operators themselves seemed really awesome! I've made some defines/templates for wrapper functions like constructors and such, but doing all the operators too (especially if you have operators with different argument types for one class) will be a big hassle :-S

Is there no longer a way to register the operators directly? will my beloved asBEHAVE_ADD and friends ever return? ;-)

Kind regards!

Wracky

Share this post


Link to post
Share on other sites
I've recently upgraded from v2.10 so I was struck by this change as well, but in fact it's just technical change. You still can register operators as opXxxx function the same way like it was with asBEHAVE (and now they are not forced to be global operators, so it's even easier). For example:

engine->RegisterObjectMethod("vec2", "vec2 opNeg() const", asMETHODPR(THVECTOR2,operator-,() const,THVECTOR2), asCALL_THISCALL);
engine->RegisterObjectMethod("vec2", "vec2& opAddAssign(const vec2 &in)", asMETHOD(THVECTOR2,operator+=), asCALL_THISCALL);

//or
engine->RegisterObjectMethod("vec2", "vec2 opAdd(const vec2 &in) const", asFUNCTIONPR(operator+, (const THVECTOR2&, const THVECTOR2&), THVECTOR2), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("vec2", "vec2 opMul(const float) const", asFUNCTIONPR(operator*, (const THVECTOR2&, const THFLOAT), THVECTOR2), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("vec2", "vec2 opMul_r(const float) const", asFUNCTIONPR(operator*, (const THFLOAT, const THVECTOR2&), THVECTOR2), asCALL_CDECL_OBJLAST);

Share this post


Link to post
Share on other sites

This topic is 2543 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this