Greetings. I've been using std string type (through RegisterStdString) and UTF-8. I can get any Unicode characters FROM script without any problems (I convert from ASCII ordering to UTF8 ordering and insert result in wstring). Non English characters come through just fine.
But I can't figure out how to go the other way, passing string as an argument to a script function. I can still do it with SetArgObject if the characters' code range is in ASCII, but not outside this range (non English Unicode characters).
I have 2 questions. What's the simplest way to achieve this with my current setting? What's the proper way to do it?
[Edited by - jgrey on November 27, 2010 2:33:37 PM]
*SOLVED* Passing unicode as function argument
Can you show an example of passing a string to a script function that isn't working?
Thank you for your reply SiCrane.
I somehow got it to work now, but it's one of those #'$&%(~@! moments of programming, where I can't tell what the hell I've done differently. Last night this didn't work and I've tried it in so many obfuscated ways just to see if any of them work.
Perhaps I had got the length wrong or something which is the most likely explanation. Or perhaps some of my endian experiments had left over codes and interfered. I really don't know. For gods sake :(
Just so that somebody in the future might be helped, I've tested this with east asian characters and works (use UTF-8 format on your script file as well).
With std string set up through RegisterStdString(m_ScriptEngine):
Thank you anyways, to all those who may have given it a thought in an attempt to help me.
[Edited by - jgrey on November 27, 2010 2:17:19 PM]
I somehow got it to work now, but it's one of those #'$&%(~@! moments of programming, where I can't tell what the hell I've done differently. Last night this didn't work and I've tried it in so many obfuscated ways just to see if any of them work.
Perhaps I had got the length wrong or something which is the most likely explanation. Or perhaps some of my endian experiments had left over codes and interfered. I really don't know. For gods sake :(
Just so that somebody in the future might be helped, I've tested this with east asian characters and works (use UTF-8 format on your script file as well).
With std string set up through RegisterStdString(m_ScriptEngine):
// msg is wstring containing some unicode text.// Find length of the proposed conversion.int length = WideCharToMultiByte( CP_UTF8, 0, msg.c_str(), msg.length(), NULL, 0, 0, 0 ); // windows functionlength += 2; // Needed to terminate string. something like this may have been my problem last night.char *buffer = new char[length];memset( buffer, 0, length ); // wipe buffer with zeros// do the actual conversion into unicode UTF-8.WideCharToMultiByte( CP_UTF8, 0, msg.c_str(), msg.length(), buffer, length, 0, 0 );// buffer holds the result.string str(buffer); // insert into stringdelete[] buffer;// Pass the argument to script function when ready.(*context)->SetArgObject( 0, &str );// Now execute.// ... and so on.
Thank you anyways, to all those who may have given it a thought in an attempt to help me.
[Edited by - jgrey on November 27, 2010 2:17:19 PM]
Hint: You can configure AngelScript to support UTF-16 directly, which is compatible with wstring. Of course, you would have to register the std::wstring with AngelScript instead of std::string.
Regards,
Andreas
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