Skip to main content
GameDev.net gamedev.net
🔒 Locked

Custom text handling for SFML String

Started by greeniekin Oct 8, 2012 at 12:35 PM 2 replies 2.2k views
Original Post
greeniekin
greeniekin
I have been using sfml libraries and it's string class.

I really want to keep using the sfml string class though it will not work with the angelscript std string addon.

Even though if the string class is given a stdString in c++ it will convert it.

I have tried modifying the angelscript std string add on for sfml string(with some changes to sfml string)

Like the following error

error: invalid static_cast from type '' to type 'bool (*)(const sf::String&, const sf::String&)'|
for the following
r = engine->RegisterObjectMethod("string", "bool opEquals(const string ∈) const", asFUNCTIONPR(operator ==, (const sf::String &, const sf::String &), bool), asCALL_CDECL_OBJFIRST); assert( r >= 0 );

I know I can not expect you to write it or fix mine so I just have a few questions

I have not really read anything about alternative to the std string addon anywhere. I was wondering if there might be some other examples I can look at.

Also internally sfml String uses a std::basic_string to store the string. the functions that i would expose to script would be like this

int XUIElement::getAttributeInt(sf::String searchName)

Is there a way this could be used to simplify the process. I am not really sure if std string addon needs to be modified for using this type of string as opposed to just a uint8 char.
WitchLord
WitchLord
The is most likely because SFML implements the equality operator as a class method instead of a global function. Try changing the registration to the following:


r = engine->RegisterObjectMethod("string", "bool opEquals(const string ∈) const", asMETHODPR(sf::String, operator ==, (const sf::String &) const, bool), asCALL_THISCALL); assert( r >= 0 );


Hopefully it should work. If not, please post what the SFML string class looks like.

The string type is really just an ordinary type in AngelScript, and is registered just like that with the only exception being the additional string factory. I include registration for the std::string because it is the most common, but many developers use their own implementation.



std::basic_string is a completely different type than std::basic_string, a.k.a std::string, so the fact that both are implemented from the same template doesn't really make things any easier here.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
greeniekin
greeniekin
Never mind I worked out what was wrong.
I was not using namespace sf which is where the global function operators was declared.

I could get around it by using that name space or using the asFUNCTIONPR

asFUNCTIONPR(sf::operator +, (const sf::String &, const sf::String &), sf::String)


all that frustration for something so stupid.

[s]With that change i get the following as an error

error: 'operator==' is not a member of 'sf::String'|


I also think the function version matches it better.


It uses this outside of the class declaration. like so

SFML_SYSTEM_API bool operator ==(const String& left, const String& right);


There must be something really stupid I am doing

Also here is a link to the headers of sfml string.
https://github.com/L...stem/String.hpp[/s]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.