[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Managing Unicode (UTF-8 and UTF-16) data in Lua
- From: Ricardo Ramos Massaro <ricardo.massaro@...>
- Date: Tue, 9 Aug 2016 20:11:20 -0300
On Tue, Aug 9, 2016 at 4:43 PM, Egor Skriptunoff
<egor.skriptunoff@gmail.com> wrote:
> Probably, you have different fonts for different console windows?
> CP_UTF8 does not work if your console window has raster font selected
> (such as "Terminal").
You're right, I didn't have a True Type font selected on my
terminal. Using "Lucida Console" works, even though it doesn't
have the "snowman" character. It displays a single "missing
character" square for the snowman with both
WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), "snowman:
'\xE2\x98\x83'\n", 15, NULL, NULL);
and
printf("snowman: '\xE2\x98\x83'\n");
after setting the console code page to CP_UTF8. I'd never imagine
that the console refuses to change the codepage to UTF-8 just
because of the selected font, but that's what it seems to do.
So, back to the original question: Lua's print() works perfectly
fine with UTF-8, just be sure to use a True Type font on the
console and call
SetConsoleOutputCP(CP_UTF_8);
at the start of the program (but really, be a good citizen and save
the old codepage to restore it at the end of the program, like in
your example).
- Ricardo