Script: Improve 6560518

The Unicode state is not tracked using a stack instead of a raw boolean. This means that a Unicode script that e.g. updates a non-Unicode script measure will now work properly.
This commit is contained in:
Birunthan Mohanathas
2013-08-07 17:48:13 +03:00
parent 20393df751
commit a3efbbac3f
5 changed files with 29 additions and 18 deletions

View File

@@ -24,7 +24,7 @@
int LuaManager::c_RefCount = 0;
lua_State* LuaManager::c_State = 0;
bool LuaManager::c_UnicodeState = false;
std::vector<bool> LuaManager::c_UnicodeStateStack;
void LuaManager::Initialize()
{
@@ -73,14 +73,14 @@ void LuaManager::ReportErrors(const std::wstring& file)
}
std::wstring str(file, file.find_last_of(L'\\') + 1);
str += c_UnicodeState ? StringUtil::WidenUTF8(error) : StringUtil::Widen(error);
str += IsUnicodeState() ? StringUtil::WidenUTF8(error) : StringUtil::Widen(error);
LogErrorF(L"Script: %s", str.c_str());
}
void LuaManager::PushWide(const WCHAR* str)
{
lua_State* L = c_State;
const std::string narrowStr = c_UnicodeState ?
const std::string narrowStr = IsUnicodeState() ?
StringUtil::NarrowUTF8(str) : StringUtil::Narrow(str);
lua_pushlstring(L, narrowStr.c_str(), narrowStr.length());
}
@@ -88,7 +88,7 @@ void LuaManager::PushWide(const WCHAR* str)
void LuaManager::PushWide(const std::wstring& str)
{
lua_State* L = c_State;
const std::string narrowStr = c_UnicodeState ?
const std::string narrowStr = IsUnicodeState() ?
StringUtil::NarrowUTF8(str) : StringUtil::Narrow(str);
lua_pushlstring(L, narrowStr.c_str(), narrowStr.length());
}
@@ -98,6 +98,6 @@ std::wstring LuaManager::ToWide(int narg)
lua_State* L = c_State;
size_t strLen = 0;
const char* str = lua_tolstring(L, narg, &strLen);
return c_UnicodeState ?
return IsUnicodeState() ?
StringUtil::WidenUTF8(str, (int)strLen) : StringUtil::Widen(str, (int)strLen);
}