mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Lua: Fixed an issue that unneeded stack elements aren't popped.
This commit is contained in:
parent
cde1e517ac
commit
bf6d081600
@ -214,9 +214,7 @@ void CMeasureScript::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
const char* strValue = strStrVal.c_str();
|
||||
|
||||
lua_pushstring(L, strValue);
|
||||
lua_settable(L, -3);
|
||||
|
||||
lua_pushstring(L, strKey);
|
||||
lua_setfield(L, -3, strKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -266,11 +264,14 @@ void CMeasureScript::RunFunctionWithMeter(const char* p_strFunction, CMeter* p_p
|
||||
{
|
||||
LuaManager::ReportErrors(L);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
}
|
||||
|
||||
void CMeasureScript::MeterMouseEvent(CMeter* p_pMeter, MOUSE p_eMouse)
|
||||
{
|
||||
|
@ -42,12 +42,14 @@ LuaScript::LuaScript(lua_State* p_pState, const char* p_strFile, const char* p_s
|
||||
{
|
||||
m_bInitialized = false;
|
||||
LuaManager::LuaLog(LOG_ERROR, "Script: Could not run file: %s", lua_tostring(m_pState, -1));
|
||||
lua_pop(m_pState, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bInitialized = false;
|
||||
LuaManager::LuaLog(LOG_ERROR, "Script: Could not run file: %s", lua_tostring(m_pState, -1));
|
||||
lua_pop(m_pState, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,6 +87,8 @@ void LuaScript::BindVariable(const char* p_strName, void* p_pValue, const char*
|
||||
|
||||
double LuaScript::RunFunctionDouble(const char* p_strFuncName)
|
||||
{
|
||||
double result = -1;
|
||||
|
||||
if (m_bInitialized && p_strFuncName)
|
||||
{
|
||||
// Push our table onto the stack
|
||||
@ -104,21 +108,20 @@ double LuaScript::RunFunctionDouble(const char* p_strFuncName)
|
||||
LuaManager::LuaLog(LOG_ERROR, "Script: Function '%s:%s' must return a number", m_strTableName, p_strFuncName);
|
||||
}
|
||||
|
||||
double d = lua_tonumber(m_pState, -1);
|
||||
|
||||
lua_pop(m_pState, 1);
|
||||
|
||||
return d;
|
||||
result = lua_tonumber(m_pState, -1);
|
||||
}
|
||||
|
||||
lua_pop(m_pState, 1);
|
||||
// Pop both the table and the return value off the stack.
|
||||
lua_pop(m_pState, 2);
|
||||
}
|
||||
|
||||
return -1;
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring LuaScript::RunFunctionString(const char* p_strFuncName)
|
||||
{
|
||||
std::wstring result;
|
||||
|
||||
if (m_bInitialized && p_strFuncName)
|
||||
{
|
||||
// Push our table onto the stack
|
||||
@ -139,16 +142,14 @@ std::wstring LuaScript::RunFunctionString(const char* p_strFuncName)
|
||||
}
|
||||
|
||||
const char* str = lua_tostring(m_pState, -1);
|
||||
|
||||
lua_pop(m_pState, 1);
|
||||
|
||||
return ConvertToWide(str);
|
||||
result = ConvertToWide(str);
|
||||
}
|
||||
|
||||
lua_pop(m_pState, 1);
|
||||
// Pop both the table and the return value off the stack.
|
||||
lua_pop(m_pState, 2);
|
||||
}
|
||||
|
||||
return L"";
|
||||
return result;
|
||||
}
|
||||
|
||||
void LuaScript::RunFunction(const char* p_strFuncName)
|
||||
@ -182,7 +183,7 @@ bool LuaScript::FunctionExists(const char* p_strFuncName)
|
||||
// Push the function onto the stack
|
||||
lua_getfield(m_pState, -1, p_strFuncName);
|
||||
|
||||
if (lua_isfunction( m_pState, lua_gettop(m_pState)))
|
||||
if (lua_isfunction( m_pState, -1))
|
||||
{
|
||||
bExists = true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user