• Advertisement
Sign in to follow this  

Custom text handling for SFML String

This topic is 1930 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 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 '<unresolved overloaded function type>' to type 'bool (*)(const sf::String&, const sf::String&)'|
for the following
r = engine->RegisterObjectMethod("string", "bool opEquals(const string &in) 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<Uint32> 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. Edited by greeniekin

Share this post


Link to post
Share on other sites
Advertisement
The <unresolved overloaded function type> 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 &in) 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<Uint32> is a completely different type than std::basic_string<char>, a.k.a std::string, so the fact that both are implemented from the same template doesn't really make things any easier here. Edited by Andreas Jonsson

Share this post


Link to post
Share on other sites
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] Edited by greeniekin

Share this post


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

  • Advertisement