Test case:
local lfs = require("lfs") local function print_dir() for f in lfs.dir("b:\\") do print(f) end end print("Current locale: " .. os.setlocale(nil, "ctype")) os.execute("chcp") print("Кракозябры") print_dir() os.setlocale("", "ctype") print("Current locale: " .. os.setlocale(nil, "ctype")) os.execute("chcp") print("Нормальный текст") print_dir()
If you save it to a file with Win-1251 encoding and run it in the console, you’ll get this:

As you can see, after we specified Lua, which locale we are dealing with (i.e., what encoding of the file with the files and, accordingly, in what encoding of the line we have), the print function did some "under the hood" work and output In the console turned out in the right encoding. The magic is as follows:
- if the locale is not set (i.e., the default "C" -local is used), then the text is displayed as is. And since the file encoding 1251, then it is in it and displayed.
- if the locale is set, the text from the specified locale is translated into the current locale of the console (ie, from 1251 to 866).
As for ZeroBrainStudio, there the samples need to be converted to UTF-8, since it perceives all I / O as UTF-8. But, for example, the lfs module lfs system-encoded strings (1251) and in order to get readable output in the ZeroBrainStudio console, the strings need to be manually converted from 1251 to UTF-8 using some external libraries.