mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Script: Fixed that the value of the Script measure is not reset when an error occurs.
In the following case, for example, the value of the measure used to remain 10 even after an error. Now it will default to 0 on error. function Initialize() i = 0 end function Update() if i < 5 then i = i + 1 return 10 else i() -- error here, execution stops return 2 end end
This commit is contained in:
parent
b23217d840
commit
23f4a31bf0
@ -93,24 +93,13 @@ bool CMeasureScript::Update()
|
|||||||
return false;
|
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 (!m_StringValue.empty())
|
||||||
|
|
||||||
if (!ret)
|
|
||||||
{
|
{
|
||||||
// Update() didn't return anything. For backwards compatibility, check for GetStringValue() first
|
m_Value = 0;
|
||||||
if (m_HasGetStringFunction)
|
m_StringValue.clear();
|
||||||
{
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,9 +173,9 @@ void CMeasureScript::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
|||||||
tolua_pushusertype(L, m_MeterWindow, "CMeterWindow");
|
tolua_pushusertype(L, m_MeterWindow, "CMeterWindow");
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
|
|
||||||
lua_pushstring(L, "RAINMETER");
|
//lua_pushstring(L, "RAINMETER");
|
||||||
tolua_pushusertype(L, m_MeterWindow->GetMainObject(), "CRainmeter");
|
//tolua_pushusertype(L, m_MeterWindow->GetMainObject(), "CRainmeter");
|
||||||
lua_settable(L, -3);
|
//lua_settable(L, -3);
|
||||||
|
|
||||||
// Look in the properties table for values to read from the section.
|
// Look in the properties table for values to read from the section.
|
||||||
lua_getfield(L, -1, "PROPERTIES");
|
lua_getfield(L, -1, "PROPERTIES");
|
||||||
@ -197,7 +186,6 @@ void CMeasureScript::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
|||||||
while (lua_next(L, -2))
|
while (lua_next(L, -2))
|
||||||
{
|
{
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
const char* strKey = lua_tostring(L, -1);
|
const char* strKey = lua_tostring(L, -1);
|
||||||
|
|
||||||
std::wstring wstrKey = ConvertToWide(strKey);
|
std::wstring wstrKey = ConvertToWide(strKey);
|
||||||
|
@ -171,14 +171,12 @@ bool LuaScript::RunFunctionWithReturn(const char* funcName, double& numValue, st
|
|||||||
{
|
{
|
||||||
if (lua_isstring(m_State, -1))
|
if (lua_isstring(m_State, -1))
|
||||||
{
|
{
|
||||||
|
// Type is LUA_TSTRING or LUA_TNUMBER
|
||||||
const char* str = lua_tostring(m_State, -1);
|
const char* str = lua_tostring(m_State, -1);
|
||||||
strValue = ConvertToWide(str);
|
strValue = ConvertToWide(str);
|
||||||
|
|
||||||
// A number is a string and numerical string (e.g. "10") is a number, so check for it here
|
// lua_tonumber() returns 0 when type is non-number
|
||||||
if (lua_isnumber(m_State, -1))
|
numValue = lua_tonumber(m_State, -1);
|
||||||
{
|
|
||||||
numValue = lua_tonumber(m_State, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user