// class GUIWidget
result = engine->RegisterObjectType("GUIWidget", sizeof(MyGUI::Widget), asOBJ_REF ); assert_net(result>=0);
result = engine->RegisterObjectMethod("GUIWidget", "void setPosition(float , float)", asMETHODPR(MyGUI::Widget,setRealPosition,(float,float), void ), asCALL_THISCALL); assert_net(result>=0);
result = engine->RegisterObjectMethod("GUIWidget", "void setSize(float , float)", asMETHODPR(MyGUI::Widget,setRealSize,(float,float), void ), asCALL_THISCALL); assert_net(result>=0);
result = engine->RegisterObjectMethod("GUIWidget", "void setCaption(const string ∈)", asMETHOD(MyGUI::Widget,setCaption), asCALL_THISCALL); assert_net(result>=0);
result = engine->RegisterObjectMethod("GUIWidget", "const string &getName()", asMETHOD(MyGUI::Widget,getName), asCALL_THISCALL); assert_net(result>=0);
result = engine->RegisterObjectMethod("GUIWidget", "string getCaption()", asMETHOD(MyGUI::Widget,getCaption), asCALL_THISCALL); assert_net(result>=0);
result = engine->RegisterObjectBehaviour("GUIWidget", asBEHAVE_ADDREF, "void f()",asMETHOD(dummy,addRef), asCALL_THISCALL); assert_net(result>=0);
result = engine->RegisterObjectBehaviour("GUIWidget", asBEHAVE_RELEASE, "void f()",asMETHOD(dummy,release), asCALL_THISCALL); assert_net(result>=0);
attempting to pass a string to the function causes a crash, but in C++ when passing an std::string, it runs without any problems? (Since I created a wrapper function in the GUIManager class to set a widgets caption from angelscript) and now my question is: Is it possible to pass a string to this function without binding the UTFString class?
Crash when passing string to function
The title is a little vague so I'll try and describe the problem as best I can in the post.
I'm trying to bind a GUI library to Angelcode, and I've come across a problem when binding one of it's functions. The "Widget" class has a member called "setCaption" which accepts an Ogre::UTFString, and one of the UTFString constructors accepts an std::string (which is what "string" is binded to)
Here's my code for registering the function
In C++ when you do the following:
it is secretly changing it to:
AngelScript can also do the same, but then you need to register the UTFString too, and also the implicit cast behaviour.
An easier way is to simply write a wrapper function for the setCaption method, e.g:
Registered with:
Regards,
Andreas
string myCaption;widget->setCaption(myCaption);
it is secretly changing it to:
string myCaption;widget->setCaption(UTFString(myCaption));
AngelScript can also do the same, but then you need to register the UTFString too, and also the implicit cast behaviour.
An easier way is to simply write a wrapper function for the setCaption method, e.g:
void GUIWidget_setCaption(const string &str, MyGUI::Widget *widget){ widget->setCaption(str);}
Registered with:
result = engine->RegisterObjectMethod("GUIWidget", "void setCaption(const string ∈)", asFUNCTION(GUIWidget_setCaption), asCALL_CDECL_OBJLAST); assert_net(result>=0);
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement