register irrlicht-engine string

Started by
4 comments, last by WitchLord 15 years, 2 months ago
Hey Guys, ive tried to register the irrlicht string type and everything works fine besides the registration of the global behaviours.. what i have so far:

typedef irr::core::stringc string;
//RFB = return false, if condition is false

bool registerIrrStr( asEnginePtr *engine ) {

//this code is taken from stdstring.cpp

RFB( engine->RegisterObjectType("string", sizeof(string), asOBJ_VALUE | asOBJ_APP_CLASS_CDA) >= 0 );

RFB( engine->RegisterStringFactory("string", asFUNCTION(StringFactory), asCALL_CDECL) >= 0 );

RFB( engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT,  "void f()",                    asFUNCTION(ConstructString), asCALL_CDECL_OBJLAST) >= 0 );

RFB( engine->RegisterObjectBehaviour("string", asBEHAVE_DESTRUCT,   "void f()",                    asFUNCTION(DestructString),  asCALL_CDECL_OBJLAST) >= 0 );

RFB( engine->RegisterObjectBehaviour("string", asBEHAVE_ASSIGNMENT, "string&f(const string &in)", asMETHODPR(string, operator =, (const string&), string&), asCALL_THISCALL) >= 0 );

RFB( engine->RegisterObjectBehaviour("string", asBEHAVE_ADD_ASSIGN, "string&f(const string&in)", asMETHODPR(string, operator+=, (const string&), string&), asCALL_THISCALL) >= 0 );


/////so when i want to register the equal operator, compiler says:
////error C2065: '==': undeclared identifier
RFB( engine->RegisterGlobalBehaviour(asBEHAVE_EQUAL,       "bool f(const string&in, const string&in)",   asFUNCTIONPR(operator ==, (const string&, const string&), bool), asCALL_CDECL) >= 0 );

//

return true;

}

how come it does work with std::string which is basicly the same as irr::string?
Advertisement
That is indeed strange. Somehow the compiler is mistaking '==' for an identifier rather than the operator token.

You're registering the operator exactly the same way I do it in the CScriptString add-on, except that you're using an RFB macro that I'm not familiar with. Presumably to check for errors.

It could be that this macro is expanded to some invalid syntax when used with the operator ==.

How is the macro defined? Does the problem occur even if you don't use the RFB macro?

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

yep tried it your way with assert and still, he does not recognize the equal operator. i mean i could write a wrapper around it but this cant be the overall solution imo..
i also thought about problems with namespaces, since in stdstring you use
namespace std but using irrlicht´s namespace didnt solve the problem..

RFB:

#define returnfail( COND_BOOL, VFAIL ) if(!(COND_BOOL)) return VFAIL#define RFB( COND_BOOL ) returnfail(COND_BOOL,false)
Is the irrlicht string equality operator declared as a global function, or a class method?

If it is a class method, then you'll need to write a wrapper function. Still, if it was a class method the compiler error should have been that it can't find the function, not the parser error that you're getting.

What compiler are you using?

[edit]

I checked out the source for irrlicht, and the operator is indeed declared as a class method. AngelScript expects a global function, so you will indeed have to write a simple wrapper function.

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

ah ok, just for confirmation, doesnt this mean the std::string::operator== is a global function?
It does, and it is.

Just as information, a future version of AngelScript will allow both class methods and global functions for the operator behaviours.

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