mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
- Fixed: Rainmeter crashes if the Lua GetStringValue() function returns an invalid value
- Fixed: Rainmeter crashes on initialization if Lua is invalid (e.g. syntax error) - Fixed: Rainmeter crashes on mouse action if Lua file is not initialized - Fixed: Measure=SCRIPT tries to process mouse actions even if corresponding function does not exist in the Lua file causing log to fill with 'nil value' warnings - Mainly cosmetic changes to logging of erros in Measure=SCRIPT
This commit is contained in:
@ -12,7 +12,6 @@
|
||||
|
||||
#include "lua_rainmeter_ext.h"
|
||||
|
||||
|
||||
bool LuaManager::m_bInitialized = false;
|
||||
lua_State* LuaManager::m_pState = 0;
|
||||
|
||||
@ -20,7 +19,6 @@ void LuaManager::Init()
|
||||
{
|
||||
if(m_pState == 0)
|
||||
{
|
||||
|
||||
// initialize Lua
|
||||
m_pState = lua_open();
|
||||
|
||||
@ -36,7 +34,6 @@ void LuaManager::Init()
|
||||
//tolua_meter_image_open(m_pState);
|
||||
|
||||
luaopen_rainmeter_ext(m_pState);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,13 +44,11 @@ void LuaManager::CleanUp()
|
||||
|
||||
void LuaManager::ReportErrors(lua_State * L)
|
||||
{
|
||||
|
||||
LuaLog("Lua Error: %s", lua_tostring(L, -1));
|
||||
LuaLog(LOG_ERROR, "Script: %s", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
|
||||
}
|
||||
|
||||
void LuaManager::LuaLog(const char* format, ... )
|
||||
void LuaManager::LuaLog(int nLevel, const char* format, ... )
|
||||
{
|
||||
char buffer[4096];
|
||||
va_list args;
|
||||
@ -66,7 +61,7 @@ void LuaManager::LuaLog(const char* format, ... )
|
||||
_vsnprintf_s( buffer, _TRUNCATE, format, args );
|
||||
if (errno != 0)
|
||||
{
|
||||
_snprintf_s(buffer, _TRUNCATE, "LuaLog internal error: %s", format);
|
||||
_snprintf_s(buffer, _TRUNCATE, "Script: LuaLog internal error: %s", format);
|
||||
}
|
||||
|
||||
_set_invalid_parameter_handler(oldHandler);
|
||||
@ -79,6 +74,6 @@ void LuaManager::LuaLog(const char* format, ... )
|
||||
|
||||
std::wstring str = ConvertToWide(buffer);
|
||||
|
||||
LSLog(LOG_NOTICE, L"Lua", str.c_str());
|
||||
LSLog(nLevel, L"Rainmeter", str.c_str());
|
||||
va_end(args);
|
||||
}
|
@ -16,7 +16,7 @@ public:
|
||||
|
||||
static void ReportErrors(lua_State * L);
|
||||
|
||||
static void LuaLog(const char* format, ... );
|
||||
static void LuaLog(int nLevel, const char* format, ... );
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -9,7 +9,7 @@ LuaScript::LuaScript(lua_State* p_pState, const char* p_strFile, const char* p_s
|
||||
int result = luaL_loadfile(m_pState, p_strFile);
|
||||
|
||||
// If the file loaded okay.
|
||||
if(result == 0)
|
||||
if (result == 0)
|
||||
{
|
||||
// Create the table this script will reside in
|
||||
lua_newtable(m_pState);
|
||||
@ -38,20 +38,19 @@ LuaScript::LuaScript(lua_State* p_pState, const char* p_strFile, const char* p_s
|
||||
// Execute the Lua script
|
||||
result = lua_pcall(m_pState, 0, LUA_MULTRET, 0);
|
||||
|
||||
if(result)
|
||||
if (result)
|
||||
{
|
||||
m_bInitialized = false;
|
||||
LuaManager::LuaLog("Lua cannot run file:");
|
||||
LuaManager::LuaLog("%s", lua_tostring(m_pState, -1) );
|
||||
LuaManager::LuaLog(LOG_ERROR, "Script: Cannot run file: %s", p_strFile);
|
||||
LuaManager::LuaLog(LOG_ERROR, "Script: %s", lua_tostring(m_pState, -1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bInitialized = false;
|
||||
LuaManager::LuaLog("Lua cannot run file:");
|
||||
LuaManager::LuaLog("%s", lua_tostring(m_pState, -1) );
|
||||
LuaManager::LuaLog(LOG_ERROR, "Script: Cannot run file: %s", p_strFile);
|
||||
LuaManager::LuaLog(LOG_ERROR, "Script: %s", lua_tostring(m_pState, -1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LuaScript::~LuaScript(void)
|
||||
@ -61,7 +60,6 @@ LuaScript::~LuaScript(void)
|
||||
|
||||
void LuaScript::BindVariable(const char* p_strName, void* p_pValue, const char* p_strTypeName)
|
||||
{
|
||||
|
||||
PushTable();
|
||||
|
||||
/*
|
||||
@ -89,7 +87,7 @@ void LuaScript::BindVariable(const char* p_strName, void* p_pValue, const char*
|
||||
|
||||
double LuaScript::RunFunctionDouble(const char* p_strFuncName)
|
||||
{
|
||||
if( m_bInitialized && p_strFuncName )
|
||||
if (m_bInitialized && p_strFuncName)
|
||||
{
|
||||
// Push our table onto the stack
|
||||
lua_getglobal(m_pState, m_strTableName);
|
||||
@ -97,7 +95,7 @@ double LuaScript::RunFunctionDouble(const char* p_strFuncName)
|
||||
// Push the function onto the stack
|
||||
lua_getfield(m_pState,-1, p_strFuncName);
|
||||
|
||||
if( lua_pcall(m_pState, 0, 1, 0) )
|
||||
if(lua_pcall(m_pState, 0, 1, 0))
|
||||
{
|
||||
LuaManager::ReportErrors(m_pState);
|
||||
}
|
||||
@ -105,7 +103,7 @@ double LuaScript::RunFunctionDouble(const char* p_strFuncName)
|
||||
{
|
||||
if (!lua_isnumber(m_pState, -1))
|
||||
{
|
||||
LuaManager::LuaLog("Function `%s:%s' must return a number",m_strTableName, 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);
|
||||
@ -121,7 +119,6 @@ double LuaScript::RunFunctionDouble(const char* p_strFuncName)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
std::wstring LuaScript::RunFunctionString(const char* p_strFuncName)
|
||||
{
|
||||
if( m_bInitialized && p_strFuncName )
|
||||
@ -130,9 +127,9 @@ std::wstring LuaScript::RunFunctionString(const char* p_strFuncName)
|
||||
lua_getglobal(m_pState, m_strTableName);
|
||||
|
||||
// Push the function onto the stack
|
||||
lua_getfield(m_pState,-1, p_strFuncName);
|
||||
lua_getfield(m_pState, -1, p_strFuncName);
|
||||
|
||||
if( lua_pcall(m_pState, 0, 1, 0) )
|
||||
if (lua_pcall(m_pState, 0, 1, 0))
|
||||
{
|
||||
LuaManager::ReportErrors(m_pState);
|
||||
}
|
||||
@ -140,7 +137,7 @@ std::wstring LuaScript::RunFunctionString(const char* p_strFuncName)
|
||||
{
|
||||
if (!lua_isstring(m_pState, -1))
|
||||
{
|
||||
LuaManager::LuaLog("Function `%s:%s' must return a string",m_strTableName, p_strFuncName);
|
||||
LuaManager::LuaLog(LOG_ERROR, "Script: Function '%s:%s' must return a string",m_strTableName, p_strFuncName);
|
||||
}
|
||||
|
||||
const char* str = lua_tostring(m_pState, -1);
|
||||
@ -153,7 +150,7 @@ std::wstring LuaScript::RunFunctionString(const char* p_strFuncName)
|
||||
lua_pop(m_pState, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return L"";
|
||||
}
|
||||
|
||||
void LuaScript::RunFunction(const char* p_strFuncName)
|
||||
|
@ -91,7 +91,7 @@ static int AsMeterString(lua_State* tolua_S)
|
||||
static int staticLuaLog(lua_State* tolua_S)
|
||||
{
|
||||
const char* str = tolua_tostring(tolua_S,1,0);
|
||||
LuaManager::LuaLog(str);
|
||||
LuaManager::LuaLog(LOG_NOTICE, str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user