opNames
http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_class_ops.html Are those op names used in C/C++? In C/C++, I need to define only opEquals for == and != , and it is similar for opCmp ? I'd reply to this. but I couldn't http://www.gamedev.net/community/forums/topic.asp?topic_id=543844
Yes. These are used for both script declared classes and application registered classes.
For opEquals you can usually register the operator=, but with the name opEquals, e.g.
For opCmp you'll need to write a special function, e.g.
Regards,
Andreas
For opEquals you can usually register the operator=, but with the name opEquals, e.g.
engine->RegisterObjectMethod("myObj", "bool opEquals(const myObj ∈) const", asMETHOD(myObj, operator=), asCALL_THISCALL);
For opCmp you'll need to write a special function, e.g.
int opCmp(myObj &a, myObj &b){ if( a < b ) return -1; if( a > b ) return 1; return 0;}engine->RegisterObjectMethod("myObj", "int opCmp(const myObj ∈) const", asFUNCTION(opCmp), asCALL_CDECL_OBJFIRST);
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
thanks :D
I have another question
if I want both int+string & string+int I'd need both opAdd & opAdd_r. right?
Is there a difference between the following? :/
engine->RegisterObjectMethod("String", "String @ opAdd(int)", asFUNCTION(string_plus_int), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("String", "String @ opAdd_r(int)", asFUNCTION(string_plus_int), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("String", "String @ opAdd(int)", asFUNCTION(string_plus_int), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("String", "String @ opAdd_r(int)", asFUNCTION(int_plus_string), asCALL_CDECL_OBJLAST);
I have another question
if I want both int+string & string+int I'd need both opAdd & opAdd_r. right?
Is there a difference between the following? :/
engine->RegisterObjectMethod("String", "String @ opAdd(int)", asFUNCTION(string_plus_int), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("String", "String @ opAdd_r(int)", asFUNCTION(string_plus_int), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("String", "String @ opAdd(int)", asFUNCTION(string_plus_int), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("String", "String @ opAdd_r(int)", asFUNCTION(int_plus_string), asCALL_CDECL_OBJLAST);
engine->RegisterObjectMethod("String", "String @ opAdd(int)", asFUNCTION(string_plus_int), asCALL_CDECL_OBJFIRST);engine->RegisterObjectMethod("String", "String @ opAdd_r(int)", asFUNCTION(string_plus_int), asCALL_CDECL_OBJFIRST);
While correct as far as AngelScript is concerned, the operation will not give the result you expect since both functions are the same. Both 'string + int' and 'int + string' will be executed as 'string + int'.
engine->RegisterObjectMethod("String", "String @ opAdd(int)", asFUNCTION(string_plus_int), asCALL_CDECL_OBJFIRST);engine->RegisterObjectMethod("String", "String @ opAdd_r(int)", asFUNCTION(int_plus_string), asCALL_CDECL_OBJLAST);
This is correct. Now you will have the proper function executed for each operation.
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
Recommended Tutorials
Advertisement