I'm currently playing around with regsitering behaviour for implicit conversions. I tested this with the string to int conversion. But I need some clarification here, because I encountered a problem:
I regsitered the behavior like it is in the manual (except that I used the implicit version), I'm using the stdstring addon: r = engine->RegisterObjectBehaviour("string", asBEHAVE_IMPLICIT_VALUE_CAST, "int f() const", asFUNCTION(stringToInt), asCALL_CDECL_OBJLAST);
Then I registered a C++ testFunction(const int&) : void testFunction(const int&)
My test code in the script file looks like this: string testStr = "4";
//this works
testFunction(1 * testStr)
//this DON'T work
testFunction(testStr)
In the second case I get the error that there's no testFunction(string), candiates are testFunction(int&).
Does the conversion only work in operations? How do I manage it to also have it working in function calls (pass a string to a function that needs an int, for example)?
I already have convert functions that work. But I wanted to register these conveert functions as implicit conversion behavior so that AS calls them implicitly (automatically).
The implicit cast from primitive to object is still something I need to implement. It requires a way to register implicit constructors / factories to work.
Actually, it isn't a bug. The function is expecting a reference to an integer, and implicit conversions are allowed when the target type is a reference.
However, considering that the parameter is also a const, I can probably allow this conversion anyway. I'll look into this for a future release.