Advertisement

Passing Strings inline.

Started by September 07, 2014 06:08 PM
2 comments, last by PhilCK 10 years, 2 months ago

I have a function that has takes some objects by value.


sendEvent(const uint id, EventArg = EventArg(), EventArg = EventArg() .... );

EventArg has constructors for all the available types it can handle, including string.

However if I pass a string inline


sendEvent(123, "string", 1.234f);

// Generates error.
No matching signatures to 'EventManager::sendInstantEvent(const uint, const string, const float)'

// However this works.
string stringVar = "foo";
sendEvent(123, stringVar, floatVar);

EventArg is registered as a value type and has ctors for string (I tried both ref and pass by value).

I assume this might have something todo with the string addon, its not a big issue but I would like to know why this might be happening.


The Registrations


.addCtor("void f()",     asFUNCTION(EventArgCtor),  asCALL_CDECL_OBJLAST)
//.addCtor("void f(const string)",  asFUNCTION(EventArgString2Ctor),asCALL_CDECL_OBJLAST)
.addCtor("void f(const string &in)", asFUNCTION(EventArgStringCtor), asCALL_CDECL_OBJLAST)
.addCtor("void f(const float)",   asFUNCTION(EventArgFloatCtor), asCALL_CDECL_OBJLAST)
.addCtor("void f(const uint)",   asFUNCTION(EventArgUInt32Ctor), asCALL_CDECL_OBJLAST)
.addCtor("void f(const int)",   asFUNCTION(EventArgInt32Ctor), asCALL_CDECL_OBJLAST)
.addCtor("void f(const EventArg &in)", asFUNCTION(EventArgCCtor),  asCALL_CDECL_OBJLAST)
.addDtor("void f()",     asFUNCTION(EventArgDtor),  asCALL_CDECL_OBJLAST)

.addMethod("void sendInstantEvent(const uint, EventArg = EventArg(), EventArg = EventArg(), EventArg = EventArg(), EventArg = EventArg(), EventArg = EventArg(), EventArg = EventArg(), EventArg = EventArg(), EventArg = EventArg())", asMETHODPR(CaffSys::EventManager, sendInstantEvent, (const CaffSys::EventID id, CaffSys::EventArg, CaffSys::EventArg, CaffSys::EventArg, CaffSys::EventArg, CaffSys::EventArg, CaffSys::EventArg, CaffSys::EventArg, CaffSys::EventArg), void), asCALL_THISCALL)

Any ideas?

Edit
I actually get this with any type that I've added I just tried to add Vec3 which is a value type and I get the same message.

Further Edit
Hmm I can't remember why I opted for pass by type, but pass by ref (including Vec3/string) yeilds a Bad Access crash in asCContext::ExecuteNext().

I should mention that EventArg is basically (but not) boost::variant. Variant<std::nullptr_t, float, int, uint, Vec3, std::string>

I suspect it is actually a bug in the compiler, not in the add-on.

I'll take a look at it.

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

Advertisement

Ah, you're trying to trick me. wink.png


// However this works.
string stringVar = "foo";
sendEvent(123, stringVar, floatVar);

This only works because sendEvent is a different function which has matching parameters, something that sendInstantEvent doesn't.

The script language currently does not support using the object constructor to perform implicit type conversions from other object types. Implicit conversions using the constructor is only available for primitive types (since it is not possible to register value cast behaviours for those).

I'll see if can add the support for using the constructor in implicit conversions from object types too for the next release (no promises though).

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 sorry :)

Thanks for looking into it. This is just a convince function I have in C++, it isn't something I really like doing with implicit ctors.

This topic is closed to new replies.

Advertisement