Page 1 of 1

wchar definition?

Posted: Sun Mar 07, 2004 10:01 am
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

Posted: Sun Mar 07, 2004 1:23 pm
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

Posted: Sun Mar 07, 2004 1:33 pm
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