Registering Operator Overloading with Angelscript

Started by
2 comments, last by Wracky 13 years, 4 months ago
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
http://www.piko3d.net
Advertisement
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);//orengine->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);
Exactly.

The reason for this change was to allow the scripts themselves to implement operator overloading for script classes, simply by implementing the opAssign, opCmp, etc methods.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Oh Cool!! even better! Thanks!
Got a bit confused by the documentation there ;-)

Regards,
Wracky.
http://www.piko3d.net

This topic is closed to new replies.

Advertisement