From 438f79bf5de3af7bcd532de348d61777b955182a Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 27 Jan 2013 12:17:38 +0200 Subject: [PATCH] Tweaks --- Library/lua/LuaManager.cpp | 10 ++++++++-- Library/lua/LuaManager.h | 1 + Library/lua/glue/LuaMeasure.cpp | 2 +- Library/lua/glue/LuaMeter.cpp | 2 +- Library/lua/glue/LuaMeterWindow.cpp | 6 +++--- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Library/lua/LuaManager.cpp b/Library/lua/LuaManager.cpp index bad11a20..b1e8b9b9 100644 --- a/Library/lua/LuaManager.cpp +++ b/Library/lua/LuaManager.cpp @@ -75,8 +75,14 @@ void LuaManager::ReportErrors(lua_State* L, const std::wstring& file) void LuaManager::PushWide(lua_State* L, const WCHAR* str) { - const std::string tmpStr = StringUtil::Narrow(str); - lua_pushlstring(L, tmpStr.c_str(), tmpStr.length()); + const std::string narrowStr = StringUtil::Narrow(str); + lua_pushlstring(L, narrowStr.c_str(), narrowStr.length()); +} + +void LuaManager::PushWide(lua_State* L, const std::wstring& str) +{ + const std::string narrowStr = StringUtil::Narrow(str); + lua_pushlstring(L, narrowStr.c_str(), narrowStr.length()); } std::wstring LuaManager::ToWide(lua_State* L, int narg) diff --git a/Library/lua/LuaManager.h b/Library/lua/LuaManager.h index 33d0a5f5..def7fc13 100644 --- a/Library/lua/LuaManager.h +++ b/Library/lua/LuaManager.h @@ -37,6 +37,7 @@ public: static void ReportErrors(lua_State* L, const std::wstring& file); static void PushWide(lua_State* L, const WCHAR* str); + static void PushWide(lua_State* L, const std::wstring& str); static std::wstring ToWide(lua_State* L, int narg); protected: diff --git a/Library/lua/glue/LuaMeasure.cpp b/Library/lua/glue/LuaMeasure.cpp index 42f6f267..e483f236 100644 --- a/Library/lua/glue/LuaMeasure.cpp +++ b/Library/lua/glue/LuaMeasure.cpp @@ -43,7 +43,7 @@ static int GetOption(lua_State* L) std::wstring strTmp = LuaManager::ToWide(L, 2); strTmp = parser.ReadString(self->GetName(), strTmp.c_str(), LuaManager::ToWide(L, 3).c_str()); - LuaManager::PushWide(L, strTmp.c_str()); + LuaManager::PushWide(L, strTmp); return 1; } diff --git a/Library/lua/glue/LuaMeter.cpp b/Library/lua/glue/LuaMeter.cpp index ba4a3877..9b47a1c7 100644 --- a/Library/lua/glue/LuaMeter.cpp +++ b/Library/lua/glue/LuaMeter.cpp @@ -43,7 +43,7 @@ static int GetOption(lua_State* L) std::wstring strTmp = LuaManager::ToWide(L, 2); strTmp = parser.ReadString(self->GetName(), strTmp.c_str(), L""); - LuaManager::PushWide(L, strTmp.c_str()); + LuaManager::PushWide(L, strTmp); return 1; } diff --git a/Library/lua/glue/LuaMeterWindow.cpp b/Library/lua/glue/LuaMeterWindow.cpp index bc1fb63f..b55223cf 100644 --- a/Library/lua/glue/LuaMeterWindow.cpp +++ b/Library/lua/glue/LuaMeterWindow.cpp @@ -111,7 +111,7 @@ static int GetVariable(lua_State* L) const std::wstring* value = self->GetParser().GetVariable(strTmp); if (value) { - LuaManager::PushWide(L, (*value).c_str()); + LuaManager::PushWide(L, *value); } else { @@ -128,7 +128,7 @@ static int ReplaceVariables(lua_State* L) self->GetParser().ReplaceVariables(strTmp); self->GetParser().ReplaceMeasures(strTmp); - LuaManager::PushWide(L, strTmp.c_str()); + LuaManager::PushWide(L, strTmp); return 1; } @@ -206,7 +206,7 @@ static int MakePathAbsolute(lua_State* L) DECLARE_SELF(L) std::wstring path = LuaManager::ToWide(L, 2); self->MakePathAbsolute(path); - LuaManager::PushWide(L, path.c_str()); + LuaManager::PushWide(L, path); return 1; }