diff --git a/Library/MeasureScript.cpp b/Library/MeasureScript.cpp index f4853c6b..52dca406 100644 --- a/Library/MeasureScript.cpp +++ b/Library/MeasureScript.cpp @@ -93,24 +93,13 @@ bool CMeasureScript::Update() return false; } - if (m_HasUpdateFunction) + if (!(m_HasUpdateFunction && m_LuaScript->RunFunctionWithReturn(g_UpdateFunctionName, m_Value, m_StringValue)) && + !(m_HasGetStringFunction && m_LuaScript->RunFunctionWithReturn(g_GetStringFunctionName, m_Value, m_StringValue))) { - bool ret = m_LuaScript->RunFunctionWithReturn(g_UpdateFunctionName, m_Value, m_StringValue); - - if (!ret) + if (!m_StringValue.empty()) { - // Update() didn't return anything. For backwards compatibility, check for GetStringValue() first - if (m_HasGetStringFunction) - { - m_LuaScript->RunFunctionWithReturn(g_GetStringFunctionName, m_Value, m_StringValue); - } - else - { - std::wstring error = L"Script: Update() in measure ["; - error += m_Name; - error += L"] is not returning a valid number or string."; - Log(LOG_WARNING, error.c_str()); - } + m_Value = 0; + m_StringValue.clear(); } } @@ -184,9 +173,9 @@ void CMeasureScript::ReadConfig(CConfigParser& parser, const WCHAR* section) tolua_pushusertype(L, m_MeterWindow, "CMeterWindow"); lua_settable(L, -3); - lua_pushstring(L, "RAINMETER"); - tolua_pushusertype(L, m_MeterWindow->GetMainObject(), "CRainmeter"); - lua_settable(L, -3); + //lua_pushstring(L, "RAINMETER"); + //tolua_pushusertype(L, m_MeterWindow->GetMainObject(), "CRainmeter"); + //lua_settable(L, -3); // Look in the properties table for values to read from the section. lua_getfield(L, -1, "PROPERTIES"); @@ -197,7 +186,6 @@ void CMeasureScript::ReadConfig(CConfigParser& parser, const WCHAR* section) while (lua_next(L, -2)) { lua_pop(L, 1); - const char* strKey = lua_tostring(L, -1); std::wstring wstrKey = ConvertToWide(strKey); diff --git a/Library/lua/LuaScript.cpp b/Library/lua/LuaScript.cpp index fd628822..2747ff41 100644 --- a/Library/lua/LuaScript.cpp +++ b/Library/lua/LuaScript.cpp @@ -171,14 +171,12 @@ bool LuaScript::RunFunctionWithReturn(const char* funcName, double& numValue, st { if (lua_isstring(m_State, -1)) { + // Type is LUA_TSTRING or LUA_TNUMBER const char* str = lua_tostring(m_State, -1); strValue = ConvertToWide(str); - // A number is a string and numerical string (e.g. "10") is a number, so check for it here - if (lua_isnumber(m_State, -1)) - { - numValue = lua_tonumber(m_State, -1); - } + // lua_tonumber() returns 0 when type is non-number + numValue = lua_tonumber(m_State, -1); ret = true; }