mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Script:
- Added support for calling Lua functions with !PluginBang - Removed old (undocumented) implementation for handling mouse actions - Lua errors now contain the script file name only (instead of full path)
This commit is contained in:
parent
9bc238f9f2
commit
b99b275f44
@ -234,107 +234,52 @@ void CMeasureScript::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
||||
}
|
||||
}
|
||||
|
||||
void CMeasureScript::RunFunctionWithMeter(const char* p_strFunction, CMeter* p_pMeter)
|
||||
/*
|
||||
** ExecuteBang
|
||||
**
|
||||
** Sends a bang to the measure.
|
||||
**
|
||||
*/
|
||||
void CMeasureScript::ExecuteBang(const WCHAR* args)
|
||||
{
|
||||
// Get the Lua State
|
||||
lua_State* L = m_LuaScript->GetState();
|
||||
std::string function = ConvertToAscii(args);
|
||||
|
||||
// Push the script table
|
||||
m_LuaScript->PushTable();
|
||||
|
||||
// Push the function onto the stack
|
||||
lua_getfield(L, -1, p_strFunction);
|
||||
|
||||
// Check if the function exists
|
||||
if (!lua_isnil(L, -1))
|
||||
if (m_LuaScript->IsFunction(function.c_str()))
|
||||
{
|
||||
// Push the Meter
|
||||
tolua_pushusertype(L, (void*) p_pMeter, "CMeter");
|
||||
|
||||
if (lua_pcall(L, 1, 0, 0))
|
||||
{
|
||||
LuaManager::ReportErrors(L);
|
||||
}
|
||||
|
||||
lua_pop(L, 1);
|
||||
m_LuaScript->RunFunction(function.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
}
|
||||
|
||||
void CMeasureScript::MeterMouseEvent(CMeter* p_pMeter, MOUSE p_eMouse)
|
||||
{
|
||||
if (m_LuaScript && m_LuaScript->IsInitialized())
|
||||
{
|
||||
switch (p_eMouse)
|
||||
{
|
||||
case MOUSE_LMB_DOWN:
|
||||
RunFunctionWithMeter("LeftMouseDown", p_pMeter);
|
||||
break;
|
||||
|
||||
case MOUSE_LMB_UP:
|
||||
RunFunctionWithMeter("LeftMouseUp", p_pMeter);
|
||||
break;
|
||||
|
||||
case MOUSE_LMB_DBLCLK:
|
||||
RunFunctionWithMeter("LeftMouseDoubleClick", p_pMeter);
|
||||
break;
|
||||
|
||||
case MOUSE_RMB_DOWN:
|
||||
RunFunctionWithMeter("RightMouseDown", p_pMeter);
|
||||
break;
|
||||
|
||||
case MOUSE_RMB_UP:
|
||||
RunFunctionWithMeter("RightMouseUp", p_pMeter);
|
||||
break;
|
||||
|
||||
case MOUSE_RMB_DBLCLK:
|
||||
RunFunctionWithMeter("RightMouseDoubleClick", p_pMeter);
|
||||
break;
|
||||
|
||||
case MOUSE_MMB_DOWN:
|
||||
RunFunctionWithMeter("MiddleMouseDown", p_pMeter);
|
||||
break;
|
||||
|
||||
case MOUSE_MMB_UP:
|
||||
RunFunctionWithMeter("MiddleMouseUp", p_pMeter);
|
||||
break;
|
||||
|
||||
case MOUSE_MMB_DBLCLK:
|
||||
RunFunctionWithMeter("MiddleMouseDoubleClick", p_pMeter);
|
||||
break;
|
||||
}
|
||||
std::wstring error = L"Script: Function \"";
|
||||
error += args;
|
||||
error += L"\" does not exist.";
|
||||
}
|
||||
}
|
||||
|
||||
static void stackDump(lua_State *L)
|
||||
{
|
||||
int i = lua_gettop(L);
|
||||
LuaManager::LuaLog(LOG_DEBUG, " ---------------- Stack Dump ----------------" );
|
||||
while (i)
|
||||
for (int i = lua_gettop(L); i > 0; --i)
|
||||
{
|
||||
int t = lua_type(L, i);
|
||||
switch (t)
|
||||
{
|
||||
case LUA_TSTRING:
|
||||
LuaManager::LuaLog(LOG_DEBUG, "%d:`%s'", i, lua_tostring(L, i));
|
||||
LuaManager::LuaLog(LOG_DEBUG, "%d:'%s'", i, lua_tostring(L, i));
|
||||
break;
|
||||
|
||||
case LUA_TBOOLEAN:
|
||||
LuaManager::LuaLog(LOG_DEBUG, "%d: %s",i,lua_toboolean(L, i) ? "true" : "false");
|
||||
LuaManager::LuaLog(LOG_DEBUG, "%d: %s", i, lua_toboolean(L, i) ? "true" : "false");
|
||||
break;
|
||||
|
||||
case LUA_TNUMBER:
|
||||
LuaManager::LuaLog(LOG_DEBUG, "%d: %g", i, lua_tonumber(L, i));
|
||||
LuaManager::LuaLog(LOG_DEBUG, "%d: %g", i, lua_tonumber(L, i));
|
||||
break;
|
||||
|
||||
default:
|
||||
LuaManager::LuaLog(LOG_DEBUG, "%d: %s", i, lua_typename(L, t));
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
LuaManager::LuaLog(LOG_DEBUG, "--------------- Stack Dump Finished ---------------" );
|
||||
}
|
||||
|
@ -31,12 +31,10 @@ public:
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
|
||||
virtual void ExecuteBang(const WCHAR* args);
|
||||
|
||||
void DeleteLuaScript();
|
||||
|
||||
void MeterMouseEvent(CMeter* p_pMeter, MOUSE p_eMouse);
|
||||
void RunFunctionWithMeter(const char* p_strFunction, CMeter* p_pMeter);
|
||||
|
||||
protected:
|
||||
LuaScript* m_LuaScript;
|
||||
|
||||
|
@ -352,7 +352,6 @@ void CMeterWindow::Refresh(bool init, bool all)
|
||||
delete (*i);
|
||||
}
|
||||
m_Measures.clear();
|
||||
m_ScriptMeasures.clear();
|
||||
|
||||
std::list<CMeter*>::iterator j = m_Meters.begin();
|
||||
for ( ; j != m_Meters.end(); ++j)
|
||||
@ -2140,17 +2139,9 @@ bool CMeterWindow::ReadSkin()
|
||||
m_Measures.push_back(measure);
|
||||
m_Parser.AddMeasure(measure);
|
||||
|
||||
CMeasureScript* measureScript = dynamic_cast<CMeasureScript*>(measure);
|
||||
if (measureScript)
|
||||
if (!m_HasNetMeasures && dynamic_cast<CMeasureNet*>(measure))
|
||||
{
|
||||
m_ScriptMeasures.push_back(measureScript);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_HasNetMeasures && dynamic_cast<CMeasureNet*>(measure))
|
||||
{
|
||||
m_HasNetMeasures = true;
|
||||
}
|
||||
m_HasNetMeasures = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4442,12 +4433,6 @@ bool CMeterWindow::DoAction(int x, int y, MOUSE mouse, bool test)
|
||||
|
||||
if ((*j)->HitTest(x, y))
|
||||
{
|
||||
std::list<CMeasureScript*>::iterator k = m_ScriptMeasures.begin();
|
||||
for ( ; k != m_ScriptMeasures.end(); ++k)
|
||||
{
|
||||
(*k)->MeterMouseEvent((*j), mouse);
|
||||
}
|
||||
|
||||
switch (mouse)
|
||||
{
|
||||
case MOUSE_LMB_DOWN:
|
||||
|
@ -418,7 +418,6 @@ private:
|
||||
bool m_ResetRegion; // If true, the window region is recalculated during the next update
|
||||
|
||||
std::list<CMeasure*> m_Measures; // All the measures
|
||||
std::list<CMeasureScript*> m_ScriptMeasures;// All the measures
|
||||
std::list<CMeter*> m_Meters; // All the meters
|
||||
|
||||
const std::wstring m_SkinPath; // Path of the skin folder
|
||||
|
@ -67,8 +67,21 @@ void LuaManager::CleanUp()
|
||||
|
||||
void LuaManager::ReportErrors(lua_State* L)
|
||||
{
|
||||
LuaLog(LOG_ERROR, "Script: %s", lua_tostring(L, -1));
|
||||
std::string error = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Get rid of everything up to the filename
|
||||
std::string::size_type pos = 4; // Skip the drive
|
||||
pos = error.find_first_of(':', pos);
|
||||
pos = error.find_last_of('\\', pos);
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
error.erase(0, ++pos);
|
||||
}
|
||||
|
||||
std::wstring str = L"Script: ";
|
||||
str += ConvertToWide(error.c_str());
|
||||
Log(LOG_ERROR, str.c_str());
|
||||
}
|
||||
|
||||
void LuaManager::LuaLog(int nLevel, const char* format, ... )
|
||||
@ -89,15 +102,8 @@ void LuaManager::LuaLog(int nLevel, const char* format, ... )
|
||||
|
||||
_set_invalid_parameter_handler(oldHandler);
|
||||
|
||||
#ifndef _DEBUG
|
||||
// Forcing output to the Debug Output window!
|
||||
OutputDebugStringA(buffer);
|
||||
OutputDebugStringA("\n");
|
||||
#endif
|
||||
|
||||
std::wstring str = ConvertToWide(buffer);
|
||||
|
||||
LSLog(nLevel, L"Rainmeter", str.c_str());
|
||||
Log(nLevel, str.c_str());
|
||||
va_end(args);
|
||||
|
||||
delete [] buffer;
|
||||
|
@ -64,8 +64,7 @@ LuaScript::LuaScript(lua_State* state, const char* file) : m_State(state),
|
||||
if (result)
|
||||
{
|
||||
m_Initialized = false;
|
||||
LuaManager::LuaLog(LOG_ERROR, "Script: Could not run file: %s", lua_tostring(m_State, -1));
|
||||
lua_pop(m_State, 1);
|
||||
LuaManager::ReportErrors(m_State);
|
||||
|
||||
luaL_unref(m_State, LUA_GLOBALSINDEX, m_iRef);
|
||||
m_iRef = LUA_NOREF;
|
||||
@ -74,8 +73,7 @@ LuaScript::LuaScript(lua_State* state, const char* file) : m_State(state),
|
||||
else
|
||||
{
|
||||
m_Initialized = false;
|
||||
LuaManager::LuaLog(LOG_ERROR, "Script: Could not run file: %s", lua_tostring(m_State, -1));
|
||||
lua_pop(m_State, 1);
|
||||
LuaManager::ReportErrors(m_State);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,8 @@ static int Global_Log(lua_State* L)
|
||||
|
||||
static const luaL_reg TO_funcs[] =
|
||||
{
|
||||
{ "LuaLog", Global_Log }, { NULL, NULL }
|
||||
{ "LuaLog", Global_Log },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
void LuaManager::RegisterGlobal(lua_State* L)
|
||||
|
Loading…
Reference in New Issue
Block a user