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

@ -26,15 +26,25 @@ extern "C"
#include "lauxlib.h"
}
#include <vector>
class LuaManager
{
public:
class ScopedLuaState
{
public:
ScopedLuaState(bool unicode) { LuaManager::c_UnicodeStateStack.push_back(unicode); }
~ScopedLuaState() { LuaManager::c_UnicodeStateStack.pop_back(); }
operator lua_State*() { return LuaManager::c_State; }
};
static void Initialize();
static void Finalize();
static lua_State* GetState(bool unicode) { c_UnicodeState = unicode; return c_State; }
static ScopedLuaState GetState(bool unicode) { return ScopedLuaState(unicode); }
static bool IsUnicodeState() { return c_UnicodeState; }
static bool IsUnicodeState() { return c_UnicodeStateStack.back(); }
static void ReportErrors(const std::wstring& file);
@ -53,9 +63,10 @@ private:
static void RegisterMeterWindow(lua_State* L);
static void RegisterMeterString(lua_State* L);
// If set true |true|, Lua strings converted to/from as if they were encoded in UTF-8. Otherwise
// Lua strings are treated as if they are encoded in the default system encoding.
static bool c_UnicodeState;
// If the back of the vector is |true|, Lua strings converted to/from as if they were encoded
// in UTF-8. Otherwise Lua strings are treated as if they are encoded in the default system
// encoding.
static std::vector<bool> c_UnicodeStateStack;
};
#endif