- Added !CommandMeasure bang. Instead of '!PluginBang "MeasureName Arguments' use '!CommandMeasure "MeasureName" "Arguments"'.

- Script: The !CommandMeasure argument must now be Lua code. For example:
!CommandMeasure "MeasureLuaScript" "someVar = 'hello'"
!CommandMeasure "MeasureLuaScript" "SomeFunc()"
This commit is contained in:
Birunthan Mohanathas 2011-07-09 09:23:28 +00:00
parent c2e3b6292d
commit f0fbc0f145
7 changed files with 82 additions and 20 deletions

View File

@ -242,18 +242,8 @@ void CMeasureScript::ReadConfig(CConfigParser& parser, const WCHAR* section)
*/
void CMeasureScript::ExecuteBang(const WCHAR* args)
{
std::string function = ConvertToAscii(args);
if (m_LuaScript->IsFunction(function.c_str()))
{
m_LuaScript->RunFunction(function.c_str());
}
else
{
std::wstring error = L"Script: Function \"";
error += args;
error += L"\" does not exist.";
}
std::string str = ConvertToAscii(args);
m_LuaScript->RunString(str.c_str());
}
static void stackDump(lua_State *L)

View File

@ -824,7 +824,7 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
break;
case BANG_MOVE:
pos = wcschr(arg, ' ');
pos = wcschr(arg, L' ');
if (pos != NULL)
{
MoveWindow(_wtoi(arg), _wtoi(pos));
@ -879,7 +879,7 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
case BANG_LSHOOK:
{
pos = wcsrchr(arg, ' ');
pos = wcsrchr(arg, L' ');
if (pos != NULL)
{
#ifdef _WIN64
@ -905,10 +905,10 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
break;
case BANG_MOVEMETER:
pos = wcschr(arg, ' ');
pos = wcschr(arg, L' ');
if (pos != NULL)
{
pos2 = wcschr(pos + 1, ' ');
pos2 = wcschr(pos + 1, L' ');
if (pos2 != NULL)
{
MoveMeter(_wtoi(arg), _wtoi(pos), pos2 + 1);
@ -924,6 +924,34 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
}
break;
case BANG_COMMANDMEASURE:
{
std::wstring args = arg;
std::wstring measure;
std::wstring::size_type pos3;
pos3 = args.find(L' ');
if (pos3 != std::wstring::npos)
{
measure = args.substr(0, pos3);
args.erase(0, ++pos3);
CMeasure* m = GetMeasure(measure);
if (m)
{
m->ExecuteBang(args.c_str());
return;
}
LogWithArgs(LOG_WARNING, L"Unable to find [%s] for !CommandMeasure", measure.c_str());
}
else
{
Log(LOG_ERROR, L"Unable to parse parameters for !CommandMeasure");
}
}
break;
case BANG_PLUGIN:
{
std::wstring args = arg;
@ -970,7 +998,7 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg)
break;
case BANG_SETVARIABLE:
pos = wcschr(arg, ' ');
pos = wcschr(arg, L' ');
if (pos != NULL)
{
std::wstring strVariable(arg, pos - arg);

View File

@ -19,7 +19,6 @@
#ifndef __METERWINDOW_H__
#define __METERWINDOW_H__
#include <windows.h>
#include <gdiplus.h>
#include <dwmapi.h>
@ -120,6 +119,7 @@ enum BANGCOMMAND
BANG_ENABLEMEASURE,
BANG_DISABLEMEASURE,
BANG_UPDATEMEASURE,
BANG_COMMANDMEASURE,
BANG_SHOWBLUR,
BANG_HIDEBLUR,
BANG_TOGGLEBLUR,

View File

@ -680,6 +680,17 @@ void RainmeterUpdateMeasure(HWND, const char* arg)
BangWithArgs(BANG_UPDATEMEASURE, ConvertToWide(arg).c_str(), 1);
}
/*
** RainmeterCommandMeasure
**
** Callback for the !RainmeterCommandMeasure bang
**
*/
void RainmeterCommandMeasure(HWND, const char* arg)
{
BangWithArgs(BANG_COMMANDMEASURE, ConvertToWide(arg).c_str(), 2);
}
/*
** RainmeterRefresh
**
@ -2871,6 +2882,10 @@ BOOL CRainmeter::ExecuteBang(const std::wstring& bang, const std::wstring& arg,
{
BangWithArgs(BANG_UPDATEMEASURE, arg.c_str(), 1);
}
else if (_wcsicmp(name, L"CommandMeasure") == 0)
{
BangWithArgs(BANG_COMMANDMEASURE, arg.c_str(), 2);
}
else if (_wcsicmp(name, L"ShowBlur") == 0)
{
BangWithArgs(BANG_SHOWBLUR, arg.c_str(), 0);

View File

@ -61,6 +61,7 @@ void RainmeterEnableMeasure(HWND, const char* arg);
void RainmeterDisableMeasure(HWND, const char* arg);
void RainmeterToggleMeasure(HWND, const char* arg);
void RainmeterUpdateMeasure(HWND, const char* arg);
void RainmeterCommandMeasure(HWND, const char* arg);
void RainmeterActivateConfig(HWND, const char* arg);
void RainmeterDeactivateConfig(HWND, const char* arg);
void RainmeterToggleConfig(HWND, const char* arg);

View File

@ -189,6 +189,35 @@ bool LuaScript::RunFunctionWithReturn(const char* funcName, double& numValue, st
return ret;
}
/*
** RunString
**
** Runs given string in the context of the script file.
**
*/
void LuaScript::RunString(const char* str)
{
if (m_Initialized)
{
// Load the string as a Lua chunk
if (luaL_loadstring(m_State, str))
{
LuaManager::ReportErrors(m_State);
}
// Push our table onto the stack
PushTable();
// Pop table and set the environment of the loaded chunk to it
lua_setfenv(m_State, -2);
if (lua_pcall(m_State, 0, 0, 0))
{
LuaManager::ReportErrors(m_State);
}
}
}
//void LuaScript::BindVariable(const char* p_strName, void* p_pValue, const char* p_strTypeName)
//{
// PushTable();

View File

@ -33,8 +33,7 @@ public:
bool IsFunction(const char* funcName);
void RunFunction(const char* funcName);
bool RunFunctionWithReturn(const char* funcName, double& numValue, std::wstring& strValue);
static void ReportErrors(lua_State* L);
void RunString(const char* str);
protected:
lua_State* m_State;