Sign in to follow this  
Takayuki

bug? asBEHAVE_VALUE_CAST with bool

Recommended Posts

Because it might be a bug, it reports. The error occurs if bool is specified with asBEHAVE_VALUE_CAST. r = engine->RegisterObjectType("CDispatchResult", 0, asOBJ_REF); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("CDispatchResult", asBEHAVE_FACTORY, "CDispatchResult @f()", asFUNCTION(CDispatchResultWrapper::DefaultFactory), asCALL_CDECL); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("CDispatchResult", asBEHAVE_ADDREF, "void f()", asMETHOD(CDispatchResultWrapper,AddRef), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("CDispatchResult", asBEHAVE_RELEASE, "void f()", asMETHOD(CDispatchResultWrapper,Release), asCALL_THISCALL); assert( r >= 0 ); r = engine->RegisterObjectMethod("CDispatchResult", "CDispatchResult &opAssign(const CDispatchResult &in)", asMETHODPR(CDispatchResultWrapper, operator =, (const CDispatchResultWrapper&), CDispatchResultWrapper&), asCALL_THISCALL); assert( r >= 0 ); // bool r = engine->RegisterObjectMethod("CDispatchResult", "bool get_Bool() const", asMETHODPR(CDispatchResultWrapper, get_Bool, (void) const, bool),asCALL_THISCALL); assert(r>=0); /* Error*/ r = engine->RegisterObjectBehaviour("CDispatchResult", asBEHAVE_VALUE_CAST, "bool f() const", asMETHODPR(CDispatchResultWrapper, get_Bool, (void) const, bool),asCALL_THISCALL); assert(r>=0); // float r = engine->RegisterObjectMethod("CDispatchResult", "float get_Float() const", asMETHODPR(CDispatchResultWrapper, get_Float, (void) const, float),asCALL_THISCALL); assert(r>=0); /* OK */ r = engine->RegisterObjectBehaviour("CDispatchResult", asBEHAVE_VALUE_CAST, "float f() const", asMETHODPR(CDispatchResultWrapper, get_Float, (void) const, float),asCALL_THISCALL); assert(r>=0); // double r = engine->RegisterObjectMethod("CDispatchResult", "double get_Double() const", asMETHODPR(CDispatchResultWrapper, get_Double, (void) const, double),asCALL_THISCALL); assert(r>=0); /* OK */ r = engine->RegisterObjectBehaviour("CDispatchResult", asBEHAVE_VALUE_CAST, "double f() const", asMETHODPR(CDispatchResultWrapper, get_Double, (void) const, double),asCALL_THISCALL); assert(r>=0);

Share this post


Link to post
Share on other sites
This is not a bug. It is by design.

No types can be converted to or from the boolean type. I took this design because it is a very common bug for non-experienced programmers to incorrectly interpret boolean values by not explicitly comparing the value with true or false.

This is also documented in the manual, though I could probably explain it a bit better.

Share this post


Link to post
Share on other sites

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