How to register equality operator for a type.
I've been trying the example quoted from another thread:
--------------------------
std::string CompareString(const std::string &lft, const std::string &rgt)
{
return lft==rgt;
}
r = engine->RegisterObjectBehaviour(0, asBEHAVE_COMPARE, "string f(const string&, const string&)", asFUNCTION(CompareString), asCALL_CDECL); assert( r >= 0 );
--------------------------
to get the equality operator for STL strings registered. Besides the obvious(?) compilation error (CompareString's return statement conflicts with return type), I haven't had any success.. the Register(..) methods fails even when I switched the return type to bool in both the function and declaration string.
Can someone please specify a correct C++ function and a register statement for a type's equality operator?
P.S. I think it would be nice to have a doc page with examples for all global and object behaviours.
Regards
tIDE Tile Map Editorhttp://tide.codeplex.com
Sorry for bumpingmy own thread, but I found a solution:
---------------------
bool CompareString(std::string &strThis, std::string &strOther)
{
return strThis==strOther;
}
r = engine->RegisterGlobalBehaviour(asBEHAVE_EQUAL, "bool f(const string ∈, const string ∈)", asFUNCTION(CompareString), asCALL_CDECL); assert( r >= 0 );
---------------------
I've basically implemented the behaviour as global rather than object owned, and added the "in" specifier after the reference symbol (&) in the declaration. Also, I defined the return type as bool.
---------------------
bool CompareString(std::string &strThis, std::string &strOther)
{
return strThis==strOther;
}
r = engine->RegisterGlobalBehaviour(asBEHAVE_EQUAL, "bool f(const string ∈, const string ∈)", asFUNCTION(CompareString), asCALL_CDECL); assert( r >= 0 );
---------------------
I've basically implemented the behaviour as global rather than object owned, and added the "in" specifier after the reference symbol (&) in the declaration. Also, I defined the return type as bool.
tIDE Tile Map Editorhttp://tide.codeplex.com
Exactly.
Referring to your wish for a doc page, did you check out the manual? ;)
Application writer's manual
More specifically:
behaviours
The manual is also available in the doc folder in the sdk zip file.
Regards,
Andreas
Referring to your wish for a doc page, did you check out the manual? ;)
Application writer's manual
More specifically:
behaviours
The manual is also available in the doc folder in the sdk zip file.
Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
RTFM and all that! :)
Actually I did go through the docs, and this is what I found:
asBEHAVE_EQUAL
Equal '=='.
See addition.
So it got me confused that the function had to return 'string &' somehow (like asBEHAVE_ADD), and not a bool. Perhaps it might be worth expanding with examples for each, or at least a C++ declaration for the corresponding behaviour function in the 'behaviours' part of the doc.
Regards
Actually I did go through the docs, and this is what I found:
asBEHAVE_EQUAL
Equal '=='.
See addition.
So it got me confused that the function had to return 'string &' somehow (like asBEHAVE_ADD), and not a bool. Perhaps it might be worth expanding with examples for each, or at least a C++ declaration for the corresponding behaviour function in the 'behaviours' part of the doc.
Regards
tIDE Tile Map Editorhttp://tide.codeplex.com
I suppose I could expand upon the description a little. Thanks for the suggestion.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement