wchar definition?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Tels
Posts: 65
Joined: Fri Feb 27, 2004 7:56 pm
Location: Antarctica
Contact:

wchar definition?

Post by Tels »

Moin,

I got the problem that Perl scalars (strings) are one byte per character (on default), but functions in Irrlicht want wchar like:

device->setWindowCaption(L"Some text");

Now, L"" does of course not work in Perl :) I inquired on the Perl XS mailing list and got this answer:

- Windows has wchar_t as 16-bit and is UCS-2 or perhaps UTF-16
- Many modern UNIXes have wchar_t 32-bit and use UCS-4

What does Irrlicht use? Depends on compiler/codepage? How can I find out in a reliable manner and how to convert simple ASCII strings to the format required?

:?:

Thanx,

Tels
Perl + Irrlicht + Audiere = Game: http://bloodgate.com/perl/game
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

Irrlicht uses wchar_t's when the output needs to go to the windowing system(Windows, Linux, etc) or gui elements. It also uses c8's which are the equivalent of char.

This is how to convert between the two in c++:
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=1641
Crud, how do I do this again?
Tels
Posts: 65
Joined: Fri Feb 27, 2004 7:56 pm
Location: Antarctica
Contact:

Post by Tels »

Moin,

thank you, that works. Here is an XS (C with glue around) function that gets a Perl scalar (one byte per character) and converts it to wchar before passing it on:

Code: Select all

void
setWindowCaption(SV* classname, char* caption)
  PREINIT:
    wchar_t mytitle[512];
  CODE:
    // TODO: find out length of scalar and alloc memory for myTitle?
    mbstowcs(&mytitle[0], caption, 512);
    device->setWindowCaption(mytitle);
Works fine :)

Cheers,

Tels
Perl + Irrlicht + Audiere = Game: http://bloodgate.com/perl/game
Post Reply