Jump to content
  • Advertisement
Sign in to follow this  
virious

BUG?: Operator overloading problem

This topic is 2701 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 problem with operators overloaded in C++ and registered in AS.

I have a class called Block_Integer which is registered with flags "asOBJ_VALUE | asOBJ_APP_PRIMITIVE".

I have operator + which looks like this:


Block_Integer operator+( const Block_Integer &a, const Block_Integer &b )
{
return Block_Integer(a.m_intValue + b.m_intValue);
}


and registered like this:
engine->RegisterObjectMethod("Integer", "Integer opAdd(const Integer &in) const", asFUNCTIONPR(operator+, (const Block_Integer&, const Block_Integer&), Block_Integer), asCALL_CDECL_OBJFIRST);

My test script looks like this:
Integer intA(5), intB(7), intC;
intC = intA + intB;


When I run my script, in my operator Block_Integer argument "a" comes properly with value "5", but argument Block_Integer "b" is null. I also tried to place this operator inside my Block_Integer class (with asCALL_THISCALL calling convention) but result was the same.

Is there any issue with overloaded operators registered to AS?

I'm using AngelScript 2.20:

#define ANGELSCRIPT_VERSION 22000
#define ANGELSCRIPT_VERSION_STRING "2.20.0 WIP"

Share this post


Link to post
Share on other sites
Advertisement
I'm no expert, but I think asOBJ_APP_PRIMITIVE is reserved for truly primitive C++ types and not class like your Block_Integer. I guess that you have at least an assignment operator in your class and a constructor in order to make your declaration and "intC = intA + intB" to compile, so somewhere you might wanna have a "asOBJ_APP_CLASS_*" in your declartion flag (http://www.angelcode.com/angelscript/sdk/docs/manual/angelscript_8h.html#855d86fa9ee15b9f75e553ee376b5c7af15f3dd82be0e77e05ee0dbea096bb36)
Anyway, just to be sure I tried to reproduce your problem, and I did with flags "asOBJ_VALUE | asOBJ_APP_PRIMITIVE", but it worked fine with flags "asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CA"

Note to self: remember to never ever again try to paste some italic code in a message body...

Share this post


Link to post
Share on other sites
I'm not aware of any issues with overloaded operators in AngelScript, but I'll investigate this to see if I can reproduce the problem you reported.Can you tell me a bit more about how the Block_Integer class is declared in the C++ application? You say it is a class, but you registered it as if it was a primitive. Quittouff is correct, asOBJ_APP_PRIMITIVE is only meant for primitive C++ datatypes (except float/double), all classes and structures should be registered with the asOBJ_APP_CLASS flag + respective flag for constructor, destructor, assignment operator, and or copy constructor.

Share this post


Link to post
Share on other sites
I solved this problem. I just changed flags to "asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CA", added assignment operator (without registering it to AS) and it works fine now. So in this case the problem were: wrong flags and missing assignment operator. And additionally I've registered the default constructor.

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!