Utf8 in the Lua standalone interpreter on Windows
Stephen Hewitt <[email protected]> Fri, 24 Apr 2026 09:55:03 -0700 (PDT)
| Newsgroups | gmane.comp.lang.lua.general |
|---|---|
| Message-ID | <[email protected]> |
Currently on Windows you can't open a file that contains utf8 characters
in the standalone interpreter.Similarly, the console chokes on utf8. For me
this fixes it (lua.c):
#ifndef LUA_NO_UTF8_IN_STANDALONE_INTERPRETER
#include <fcntl.h>
#include <locale.h>
static void setup_utf8() {
setlocale(LC_ALL, ".UTF-8");
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
_setmode(_fileno(stdout), _O_BINARY);
_setmode(_fileno(stdin), _O_BINARY);
}
#else
static void setup_utf8() {}
#endif
AND
int main (int argc, char **argv) {
int status, result;
lua_State *L = luaL_newstate(); /* create state */
setup_utf8();
Sww here for more context: https://github.com/lua/lua/compare/master...
shewitt-au:lua:windows
--
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/76698565-adca-4756-b1fd-ba04c16e6ed9n%40googlegroups.com.