lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 13/01/2021 11:30, Marcus Mason wrote:
> Hi, as I'm sure the windows users on the list are aware, the lua
> standalone application often struggles with mojibake when printing to
> the windows terminal. To be clear, this is a problem with windows
> consoles specifically, and somewhat ironically using lua from within a
> WSL session leads to no mojibake. The windows function
> SetConsoleOutputCP "Sets the output code page used by the console
> associated with the calling process."  which may be useful in correctly
> printing from lua by selecting the utf8 codepage. Has anyone looked into
> something like this before?


This would only work on very recent version of Windows (I think Win10
v2004, maybe), and not very reliably.

However, you don't need the direct Win32 system call, you can use the
`chcp` command:


-- Set console output to UTF8
os.execute"chcp 65001"
-- print 'Ναί' (Greek 'yes') in UTF8
print(string.char(0xce, 0x9d, 0xce, 0xb1, 0xce, 0xaf))
-- print '番号' (Japanese 'no') in UTF8
print(string.char(0xe7, 0x95, 0xaa, 0xe5, 0x8f, 0xb7))


And there's still issues with input.

They may fix things in the future, or with a replacement terminal[1]
util. But who knows?

Scott

[1]https://github.com/microsoft/terminal