Jump to content
  • Advertisement
Sign in to follow this  
PhilCK

Passing Strings inline.

This topic is 1465 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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>

Edited by PhilCK

Share this post


Link to post
Share on other sites
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).

Edited by Andreas Jonsson

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!