mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Script: Change Unicode script support to require UTF-16 LE files rather than UTF-8
This commit is contained in:
parent
d0466c5588
commit
20393df751
@ -55,21 +55,21 @@ bool LuaScript::Initialize(const std::wstring& scriptFile)
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
file = nullptr;
|
file = nullptr;
|
||||||
|
|
||||||
// Has UTF8 BOM, so assume that data is already in UTF8.
|
lua_State* L = GetState();
|
||||||
char* scriptData = (char*)fileData;
|
bool scriptLoaded = false;
|
||||||
int scriptDataSize = fileSize;
|
|
||||||
|
|
||||||
// Treat the script as Unicode if it has the UTF-8 BOM.
|
// Treat the script as Unicode if it has the UTF-16 LE BOM.
|
||||||
m_Unicode = fileSize > 3 && fileData[0] == 0xEF && fileData[1] == 0xBB && fileData[2] == 0xBF;
|
m_Unicode = fileSize > 2 && fileData[0] == 0xFF && fileData[1] == 0xFE;
|
||||||
if (m_Unicode)
|
if (m_Unicode)
|
||||||
{
|
{
|
||||||
// Skip the BOM.
|
const std::string utf8Data =
|
||||||
scriptData += 3;
|
StringUtil::NarrowUTF8((WCHAR*)(fileData + 2), (fileSize - 2) / sizeof(WCHAR));
|
||||||
scriptDataSize -= 3;
|
scriptLoaded = luaL_loadbuffer(L, utf8Data.c_str(), utf8Data.length(), "") == 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scriptLoaded = luaL_loadbuffer(L, (char*)fileData, fileSize, "") == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_State* L = GetState();
|
|
||||||
bool scriptLoaded = luaL_loadbuffer(L, scriptData, scriptDataSize, "") == 0;
|
|
||||||
|
|
||||||
delete [] fileData;
|
delete [] fileData;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user