Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Custom text handling for SFML String


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 greeniekin   Members   -  Reputation: 141

Like
0Likes
Like

Posted 08 October 2012 - 06:35 AM

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, 08 October 2012 - 07:26 AM.


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3239

Like
0Likes
Like

Posted 08 October 2012 - 06:55 AM

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, 08 October 2012 - 06:56 AM.

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

#3 greeniekin   Members   -  Reputation: 141

Like
0Likes
Like

Posted 08 October 2012 - 10:59 AM

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.

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

Edited by greeniekin, 08 October 2012 - 12:49 PM.


#4 Andreas Jonsson   Moderators   -  Reputation: 3239

Like
0Likes
Like

Posted 09 October 2012 - 07:57 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS