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,96 +234,42 @@ 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
|
std::string function = ConvertToAscii(args);
|
||||||
lua_State* L = m_LuaScript->GetState();
|
|
||||||
|
|
||||||
// Push the script table
|
if (m_LuaScript->IsFunction(function.c_str()))
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
// Push the Meter
|
m_LuaScript->RunFunction(function.c_str());
|
||||||
tolua_pushusertype(L, (void*) p_pMeter, "CMeter");
|
|
||||||
|
|
||||||
if (lua_pcall(L, 1, 0, 0))
|
|
||||||
{
|
|
||||||
LuaManager::ReportErrors(L);
|
|
||||||
}
|
|
||||||
|
|
||||||
lua_pop(L, 1);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lua_pop(L, 2);
|
std::wstring error = L"Script: Function \"";
|
||||||
}
|
error += args;
|
||||||
}
|
error += L"\" does not exist.";
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stackDump(lua_State *L)
|
static void stackDump(lua_State *L)
|
||||||
{
|
{
|
||||||
int i = lua_gettop(L);
|
|
||||||
LuaManager::LuaLog(LOG_DEBUG, " ---------------- Stack Dump ----------------" );
|
LuaManager::LuaLog(LOG_DEBUG, " ---------------- Stack Dump ----------------" );
|
||||||
while (i)
|
for (int i = lua_gettop(L); i > 0; --i)
|
||||||
{
|
{
|
||||||
int t = lua_type(L, i);
|
int t = lua_type(L, i);
|
||||||
switch (t)
|
switch (t)
|
||||||
{
|
{
|
||||||
case LUA_TSTRING:
|
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;
|
break;
|
||||||
|
|
||||||
case LUA_TBOOLEAN:
|
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;
|
break;
|
||||||
|
|
||||||
case LUA_TNUMBER:
|
case LUA_TNUMBER:
|
||||||
@ -334,7 +280,6 @@ static void stackDump(lua_State *L)
|
|||||||
LuaManager::LuaLog(LOG_DEBUG, "%d: %s", i, lua_typename(L, t));
|
LuaManager::LuaLog(LOG_DEBUG, "%d: %s", i, lua_typename(L, t));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i--;
|
|
||||||
}
|
}
|
||||||
LuaManager::LuaLog(LOG_DEBUG, "--------------- Stack Dump Finished ---------------" );
|
LuaManager::LuaLog(LOG_DEBUG, "--------------- Stack Dump Finished ---------------" );
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,10 @@ public:
|
|||||||
virtual void Initialize();
|
virtual void Initialize();
|
||||||
virtual bool Update();
|
virtual bool Update();
|
||||||
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
|
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
|
||||||
|
virtual void ExecuteBang(const WCHAR* args);
|
||||||
|
|
||||||
void DeleteLuaScript();
|
void DeleteLuaScript();
|
||||||
|
|
||||||
void MeterMouseEvent(CMeter* p_pMeter, MOUSE p_eMouse);
|
|
||||||
void RunFunctionWithMeter(const char* p_strFunction, CMeter* p_pMeter);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LuaScript* m_LuaScript;
|
LuaScript* m_LuaScript;
|
||||||
|
|
||||||
|
@ -352,7 +352,6 @@ void CMeterWindow::Refresh(bool init, bool all)
|
|||||||
delete (*i);
|
delete (*i);
|
||||||
}
|
}
|
||||||
m_Measures.clear();
|
m_Measures.clear();
|
||||||
m_ScriptMeasures.clear();
|
|
||||||
|
|
||||||
std::list<CMeter*>::iterator j = m_Meters.begin();
|
std::list<CMeter*>::iterator j = m_Meters.begin();
|
||||||
for ( ; j != m_Meters.end(); ++j)
|
for ( ; j != m_Meters.end(); ++j)
|
||||||
@ -2140,20 +2139,12 @@ bool CMeterWindow::ReadSkin()
|
|||||||
m_Measures.push_back(measure);
|
m_Measures.push_back(measure);
|
||||||
m_Parser.AddMeasure(measure);
|
m_Parser.AddMeasure(measure);
|
||||||
|
|
||||||
CMeasureScript* measureScript = dynamic_cast<CMeasureScript*>(measure);
|
|
||||||
if (measureScript)
|
|
||||||
{
|
|
||||||
m_ScriptMeasures.push_back(measureScript);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!m_HasNetMeasures && dynamic_cast<CMeasureNet*>(measure))
|
if (!m_HasNetMeasures && dynamic_cast<CMeasureNet*>(measure))
|
||||||
{
|
{
|
||||||
m_HasNetMeasures = true;
|
m_HasNetMeasures = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (CError& error)
|
catch (CError& error)
|
||||||
{
|
{
|
||||||
delete measure;
|
delete measure;
|
||||||
@ -4442,12 +4433,6 @@ bool CMeterWindow::DoAction(int x, int y, MOUSE mouse, bool test)
|
|||||||
|
|
||||||
if ((*j)->HitTest(x, y))
|
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)
|
switch (mouse)
|
||||||
{
|
{
|
||||||
case MOUSE_LMB_DOWN:
|
case MOUSE_LMB_DOWN:
|
||||||
|
@ -418,7 +418,6 @@ private:
|
|||||||
bool m_ResetRegion; // If true, the window region is recalculated during the next update
|
bool m_ResetRegion; // If true, the window region is recalculated during the next update
|
||||||
|
|
||||||
std::list<CMeasure*> m_Measures; // All the measures
|
std::list<CMeasure*> m_Measures; // All the measures
|
||||||
std::list<CMeasureScript*> m_ScriptMeasures;// All the measures
|
|
||||||
std::list<CMeter*> m_Meters; // All the meters
|
std::list<CMeter*> m_Meters; // All the meters
|
||||||
|
|
||||||
const std::wstring m_SkinPath; // Path of the skin folder
|
const std::wstring m_SkinPath; // Path of the skin folder
|
||||||
|
@ -67,8 +67,21 @@ void LuaManager::CleanUp()
|
|||||||
|
|
||||||
void LuaManager::ReportErrors(lua_State* L)
|
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);
|
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, ... )
|
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);
|
_set_invalid_parameter_handler(oldHandler);
|
||||||
|
|
||||||
#ifndef _DEBUG
|
|
||||||
// Forcing output to the Debug Output window!
|
|
||||||
OutputDebugStringA(buffer);
|
|
||||||
OutputDebugStringA("\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::wstring str = ConvertToWide(buffer);
|
std::wstring str = ConvertToWide(buffer);
|
||||||
|
Log(nLevel, str.c_str());
|
||||||
LSLog(nLevel, L"Rainmeter", str.c_str());
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
|
@ -64,8 +64,7 @@ LuaScript::LuaScript(lua_State* state, const char* file) : m_State(state),
|
|||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
m_Initialized = false;
|
m_Initialized = false;
|
||||||
LuaManager::LuaLog(LOG_ERROR, "Script: Could not run file: %s", lua_tostring(m_State, -1));
|
LuaManager::ReportErrors(m_State);
|
||||||
lua_pop(m_State, 1);
|
|
||||||
|
|
||||||
luaL_unref(m_State, LUA_GLOBALSINDEX, m_iRef);
|
luaL_unref(m_State, LUA_GLOBALSINDEX, m_iRef);
|
||||||
m_iRef = LUA_NOREF;
|
m_iRef = LUA_NOREF;
|
||||||
@ -74,8 +73,7 @@ LuaScript::LuaScript(lua_State* state, const char* file) : m_State(state),
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Initialized = false;
|
m_Initialized = false;
|
||||||
LuaManager::LuaLog(LOG_ERROR, "Script: Could not run file: %s", lua_tostring(m_State, -1));
|
LuaManager::ReportErrors(m_State);
|
||||||
lua_pop(m_State, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ static int Global_Log(lua_State* L)
|
|||||||
|
|
||||||
static const luaL_reg TO_funcs[] =
|
static const luaL_reg TO_funcs[] =
|
||||||
{
|
{
|
||||||
{ "LuaLog", Global_Log }, { NULL, NULL }
|
{ "LuaLog", Global_Log },
|
||||||
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
void LuaManager::RegisterGlobal(lua_State* L)
|
void LuaManager::RegisterGlobal(lua_State* L)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user