【发布时间】:2020-06-12 20:52:36
【问题描述】:
我在 Windows 上工作,并且文件路径包含非 ASCII 符号。对于使用 wstring 的非 ASCII 符号窗口。我正在进行转换并将它们传递给 luaL_dofile 但它失败了,找不到文件。
这是我的代码示例:
std::wstring wstr_path = "non-ASCII path"
using convert_type = std::codecvt_utf8_utf16<wchar_t>;
std::wstring_convert<convert_type, wchar_t> converter;
std::string str_path = converter.to_bytes(wstr_path);
luaL_dofile(mRoot, str_path.c_str());
【问题讨论】:
-
我检查了来源。
luaL_dofile调用luaL_loadfilex,后者调用 Cfopen。对于 Windows C 运行时,fopen解码来自进程活动 (ANSI) 代码页的文件名并调用CreateFileW。在这里获得全部 Unicode 的唯一方法是在可执行文件的清单中将活动进程代码页设置为 UTF-8,这只能在 Windows 10 中实现。
标签: c++ windows luajit wstring