Fixed line endings and applied gitignore

This commit is contained in:
2014-07-26 09:43:40 +03:00
parent 0c57cabe56
commit 7cba5cc109
542 changed files with 112014 additions and 119759 deletions

View File

@ -1,81 +1,81 @@
/*
Copyright (C) 2010 Matt King, Birunthan Mohanathas
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "../LuaManager.h"
#include "../../Logger.h"
#include "../../../Common/StringUtil.h"
static int Print(lua_State* L)
{
// Modified version of luaB_print()
std::string message;
int n = lua_gettop(L); // Number of arguments
lua_getglobal(L, "tostring");
for (int i = 1; i <= n; ++i)
{
lua_pushvalue(L, -1); // Function to be called
lua_pushvalue(L, i); // Value to print
lua_call(L, 1, 1);
// Get result
const char* s = lua_tostring(L, -1);
if (s == nullptr)
{
return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print"));
}
if (i > 1)
{
// About dialog List View doesn't like tabs, just use 4 spaces instead
message += " ";
}
message += s;
// Pop result
lua_pop(L, 1);
}
LogDebug(LuaManager::IsUnicodeState() ?
StringUtil::WidenUTF8(message).c_str() : StringUtil::Widen(message).c_str());
return 0;
}
static int tolua_cast(lua_State* L)
{
// Simply push first argument onto stack.
lua_pushvalue(L, 1);
return 1;
}
void LuaManager::RegisterGlobal(lua_State* L)
{
lua_register(L, "print", Print);
// Register tolua.cast() for backwards compatibility.
const luaL_Reg toluaFuncs[] =
{
{ "cast", tolua_cast },
{ nullptr, nullptr }
};
luaL_register(L, "tolua", toluaFuncs);
}
/*
Copyright (C) 2010 Matt King, Birunthan Mohanathas
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "../LuaManager.h"
#include "../../Logger.h"
#include "../../../Common/StringUtil.h"
static int Print(lua_State* L)
{
// Modified version of luaB_print()
std::string message;
int n = lua_gettop(L); // Number of arguments
lua_getglobal(L, "tostring");
for (int i = 1; i <= n; ++i)
{
lua_pushvalue(L, -1); // Function to be called
lua_pushvalue(L, i); // Value to print
lua_call(L, 1, 1);
// Get result
const char* s = lua_tostring(L, -1);
if (s == nullptr)
{
return luaL_error(L, LUA_QL("tostring") " must return a string to " LUA_QL("print"));
}
if (i > 1)
{
// About dialog List View doesn't like tabs, just use 4 spaces instead
message += " ";
}
message += s;
// Pop result
lua_pop(L, 1);
}
LogDebug(LuaManager::IsUnicodeState() ?
StringUtil::WidenUTF8(message).c_str() : StringUtil::Widen(message).c_str());
return 0;
}
static int tolua_cast(lua_State* L)
{
// Simply push first argument onto stack.
lua_pushvalue(L, 1);
return 1;
}
void LuaManager::RegisterGlobal(lua_State* L)
{
lua_register(L, "print", Print);
// Register tolua.cast() for backwards compatibility.
const luaL_Reg toluaFuncs[] =
{
{ "cast", tolua_cast },
{ nullptr, nullptr }
};
luaL_register(L, "tolua", toluaFuncs);
}

View File

@ -1,158 +1,158 @@
/*
Copyright (C) 2010 Matt King, Birunthan Mohanathas
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "../LuaManager.h"
#include "../../Measure.h"
#include "../../MeterWindow.h"
#define DECLARE_SELF(L) \
void* selfData = lua_touserdata(L, 1); \
if (!selfData) return 0; \
Measure* self = *(Measure**)selfData;
static int GetName(lua_State* L)
{
DECLARE_SELF(L)
LuaManager::PushWide(self->GetName());
return 1;
}
static int GetOption(lua_State* L)
{
DECLARE_SELF(L)
MeterWindow* meterWindow = self->GetMeterWindow();
ConfigParser& parser = meterWindow->GetParser();
const std::wstring section = LuaManager::ToWide(2);
const std::wstring defValue = LuaManager::ToWide(3);
const std::wstring& value =
parser.ReadString(self->GetName(), section.c_str(), defValue.c_str());
LuaManager::PushWide(value);
return 1;
}
static int GetNumberOption(lua_State* L)
{
DECLARE_SELF(L)
MeterWindow* meterWindow = self->GetMeterWindow();
ConfigParser& parser = meterWindow->GetParser();
std::wstring strTmp = LuaManager::ToWide(2);
double value = parser.ReadFloat(self->GetName(), strTmp.c_str(), lua_tonumber(L, 3));
lua_pushnumber(L, value);
return 1;
}
static int Disable(lua_State* L)
{
DECLARE_SELF(L)
self->Disable();
return 0;
}
static int Enable(lua_State* L)
{
DECLARE_SELF(L)
self->Enable();
return 0;
}
static int GetValue(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetValue());
return 1;
}
static int GetRelativeValue(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetRelativeValue());
return 1;
}
static int GetValueRange(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetValueRange());
return 1;
}
static int GetMinValue(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetMinValue());
return 1;
}
static int GetMaxValue(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetMaxValue());
return 1;
}
static int GetStringValue(lua_State* L)
{
DECLARE_SELF(L)
int top = lua_gettop(L);
AUTOSCALE autoScale = (top > 1) ? (AUTOSCALE)(int)lua_tonumber(L, 2) : AUTOSCALE_OFF;
double scale = (top > 2) ? lua_tonumber(L, 3) : 1.0;
int decimals = (int)lua_tonumber(L, 4);
bool percentual = lua_toboolean(L, 5) != 0;
const WCHAR* val = self->GetStringOrFormattedValue(autoScale, scale, decimals, percentual);
LuaManager::PushWide(val);
return 1;
}
void LuaManager::RegisterMeasure(lua_State* L)
{
const luaL_Reg functions[] =
{
{ "GetName", GetName },
{ "GetOption", GetOption },
{ "GetNumberOption", GetNumberOption },
{ "Disable", Disable },
{ "Enable", Enable },
{ "GetValue", GetValue },
{ "GetRelativeValue", GetRelativeValue },
{ "GetValueRange", GetValueRange },
{ "GetMinValue", GetMinValue },
{ "GetMaxValue", GetMaxValue },
{ "GetStringValue", GetStringValue },
{ nullptr, nullptr }
};
luaL_register(L, "Measure", functions);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
lua_pop(L, 1);
}
/*
Copyright (C) 2010 Matt King, Birunthan Mohanathas
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "../LuaManager.h"
#include "../../Measure.h"
#include "../../MeterWindow.h"
#define DECLARE_SELF(L) \
void* selfData = lua_touserdata(L, 1); \
if (!selfData) return 0; \
Measure* self = *(Measure**)selfData;
static int GetName(lua_State* L)
{
DECLARE_SELF(L)
LuaManager::PushWide(self->GetName());
return 1;
}
static int GetOption(lua_State* L)
{
DECLARE_SELF(L)
MeterWindow* meterWindow = self->GetMeterWindow();
ConfigParser& parser = meterWindow->GetParser();
const std::wstring section = LuaManager::ToWide(2);
const std::wstring defValue = LuaManager::ToWide(3);
const std::wstring& value =
parser.ReadString(self->GetName(), section.c_str(), defValue.c_str());
LuaManager::PushWide(value);
return 1;
}
static int GetNumberOption(lua_State* L)
{
DECLARE_SELF(L)
MeterWindow* meterWindow = self->GetMeterWindow();
ConfigParser& parser = meterWindow->GetParser();
std::wstring strTmp = LuaManager::ToWide(2);
double value = parser.ReadFloat(self->GetName(), strTmp.c_str(), lua_tonumber(L, 3));
lua_pushnumber(L, value);
return 1;
}
static int Disable(lua_State* L)
{
DECLARE_SELF(L)
self->Disable();
return 0;
}
static int Enable(lua_State* L)
{
DECLARE_SELF(L)
self->Enable();
return 0;
}
static int GetValue(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetValue());
return 1;
}
static int GetRelativeValue(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetRelativeValue());
return 1;
}
static int GetValueRange(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetValueRange());
return 1;
}
static int GetMinValue(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetMinValue());
return 1;
}
static int GetMaxValue(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetMaxValue());
return 1;
}
static int GetStringValue(lua_State* L)
{
DECLARE_SELF(L)
int top = lua_gettop(L);
AUTOSCALE autoScale = (top > 1) ? (AUTOSCALE)(int)lua_tonumber(L, 2) : AUTOSCALE_OFF;
double scale = (top > 2) ? lua_tonumber(L, 3) : 1.0;
int decimals = (int)lua_tonumber(L, 4);
bool percentual = lua_toboolean(L, 5) != 0;
const WCHAR* val = self->GetStringOrFormattedValue(autoScale, scale, decimals, percentual);
LuaManager::PushWide(val);
return 1;
}
void LuaManager::RegisterMeasure(lua_State* L)
{
const luaL_Reg functions[] =
{
{ "GetName", GetName },
{ "GetOption", GetOption },
{ "GetNumberOption", GetNumberOption },
{ "Disable", Disable },
{ "Enable", Enable },
{ "GetValue", GetValue },
{ "GetRelativeValue", GetRelativeValue },
{ "GetValueRange", GetValueRange },
{ "GetMinValue", GetMinValue },
{ "GetMaxValue", GetMaxValue },
{ "GetStringValue", GetStringValue },
{ nullptr, nullptr }
};
luaL_register(L, "Measure", functions);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
lua_pop(L, 1);
}

View File

@ -1,175 +1,175 @@
/*
Copyright (C) 2010 Matt King, Birunthan Mohanathas
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "../LuaManager.h"
#include "../../Meter.h"
#include "../../MeterString.h"
#define DECLARE_SELF(L) \
void* selfData = lua_touserdata(L, 1); \
if (!selfData) return 0; \
Meter* self = *(Meter**)selfData;
static int GetName(lua_State* L)
{
DECLARE_SELF(L)
LuaManager::PushWide(self->GetName());
return 1;
}
static int GetOption(lua_State* L)
{
DECLARE_SELF(L)
MeterWindow* meterWindow = self->GetMeterWindow();
ConfigParser& parser = meterWindow->GetParser();
const std::wstring section = LuaManager::ToWide(2);
const std::wstring defValue = LuaManager::ToWide(3);
const std::wstring& value =
parser.ReadString(self->GetName(), section.c_str(), defValue.c_str());
LuaManager::PushWide(value);
return 1;
}
static int GetW(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetW());
return 1;
}
static int GetH(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetH());
return 1;
}
static int GetX(lua_State* L)
{
DECLARE_SELF(L)
const bool abs = lua_toboolean(L, 2) != 0;
lua_pushnumber(L, self->GetX(abs));
return 1;
}
static int GetY(lua_State* L)
{
DECLARE_SELF(L)
const bool abs = lua_toboolean(L, 2) != 0;
lua_pushnumber(L, self->GetY(abs));
return 1;
}
static int SetW(lua_State* L)
{
DECLARE_SELF(L)
int w = (int)lua_tonumber(L, 2);
self->SetW(w);
return 0;
}
static int SetH(lua_State* L)
{
DECLARE_SELF(L)
int h = (int)lua_tonumber(L, 2);
self->SetH(h);
return 0;
}
static int SetX(lua_State* L)
{
DECLARE_SELF(L)
int x = (int)lua_tonumber(L, 2);
self->SetX(x);
return 0;
}
static int SetY(lua_State* L)
{
DECLARE_SELF(L)
int y = (int)lua_tonumber(L, 2);
self->SetY(y);
return 0;
}
static int Hide(lua_State* L)
{
DECLARE_SELF(L)
self->Hide();
return 0;
}
static int Show(lua_State* L)
{
DECLARE_SELF(L)
self->Show();
return 0;
}
static int SetText(lua_State* L)
{
DECLARE_SELF(L)
if (self->GetTypeID() == TypeID<MeterString>())
{
MeterString* string = (MeterString*)self;
std::wstring str = LuaManager::ToWide(2);
string->SetText(str.c_str());
}
return 0;
}
void LuaManager::RegisterMeter(lua_State* L)
{
const luaL_Reg functions[] =
{
{ "GetName", GetName },
{ "GetOption", GetOption },
{ "GetW", GetW },
{ "GetH", GetH },
{ "GetX", GetX },
{ "GetY", GetY },
{ "SetW", SetW },
{ "SetH", SetH },
{ "SetX", SetX },
{ "SetY", SetY },
{ "Hide", Hide },
{ "Show", Show },
{ "SetText", SetText },
{ nullptr, nullptr }
};
luaL_register(L, "Meter", functions);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
lua_pop(L, 1);
}
/*
Copyright (C) 2010 Matt King, Birunthan Mohanathas
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "../LuaManager.h"
#include "../../Meter.h"
#include "../../MeterString.h"
#define DECLARE_SELF(L) \
void* selfData = lua_touserdata(L, 1); \
if (!selfData) return 0; \
Meter* self = *(Meter**)selfData;
static int GetName(lua_State* L)
{
DECLARE_SELF(L)
LuaManager::PushWide(self->GetName());
return 1;
}
static int GetOption(lua_State* L)
{
DECLARE_SELF(L)
MeterWindow* meterWindow = self->GetMeterWindow();
ConfigParser& parser = meterWindow->GetParser();
const std::wstring section = LuaManager::ToWide(2);
const std::wstring defValue = LuaManager::ToWide(3);
const std::wstring& value =
parser.ReadString(self->GetName(), section.c_str(), defValue.c_str());
LuaManager::PushWide(value);
return 1;
}
static int GetW(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetW());
return 1;
}
static int GetH(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetH());
return 1;
}
static int GetX(lua_State* L)
{
DECLARE_SELF(L)
const bool abs = lua_toboolean(L, 2) != 0;
lua_pushnumber(L, self->GetX(abs));
return 1;
}
static int GetY(lua_State* L)
{
DECLARE_SELF(L)
const bool abs = lua_toboolean(L, 2) != 0;
lua_pushnumber(L, self->GetY(abs));
return 1;
}
static int SetW(lua_State* L)
{
DECLARE_SELF(L)
int w = (int)lua_tonumber(L, 2);
self->SetW(w);
return 0;
}
static int SetH(lua_State* L)
{
DECLARE_SELF(L)
int h = (int)lua_tonumber(L, 2);
self->SetH(h);
return 0;
}
static int SetX(lua_State* L)
{
DECLARE_SELF(L)
int x = (int)lua_tonumber(L, 2);
self->SetX(x);
return 0;
}
static int SetY(lua_State* L)
{
DECLARE_SELF(L)
int y = (int)lua_tonumber(L, 2);
self->SetY(y);
return 0;
}
static int Hide(lua_State* L)
{
DECLARE_SELF(L)
self->Hide();
return 0;
}
static int Show(lua_State* L)
{
DECLARE_SELF(L)
self->Show();
return 0;
}
static int SetText(lua_State* L)
{
DECLARE_SELF(L)
if (self->GetTypeID() == TypeID<MeterString>())
{
MeterString* string = (MeterString*)self;
std::wstring str = LuaManager::ToWide(2);
string->SetText(str.c_str());
}
return 0;
}
void LuaManager::RegisterMeter(lua_State* L)
{
const luaL_Reg functions[] =
{
{ "GetName", GetName },
{ "GetOption", GetOption },
{ "GetW", GetW },
{ "GetH", GetH },
{ "GetX", GetX },
{ "GetY", GetY },
{ "SetW", SetW },
{ "SetH", SetH },
{ "SetX", SetX },
{ "SetY", SetY },
{ "Hide", Hide },
{ "Show", Show },
{ "SetText", SetText },
{ nullptr, nullptr }
};
luaL_register(L, "Meter", functions);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
lua_pop(L, 1);
}

View File

@ -1,240 +1,240 @@
/*
Copyright (C) 2010 Matt King, Birunthan Mohanathas
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "../LuaManager.h"
#include "../../Rainmeter.h"
#include "../../MeterWindow.h"
#include "../../MeterString.h"
#define DECLARE_SELF(L) \
void* selfData = lua_touserdata(L, 1); \
if (!selfData) return 0; \
MeterWindow* self = *(MeterWindow**)selfData;
static int Bang(lua_State* L)
{
DECLARE_SELF(L)
ConfigParser& parser = self->GetParser();
std::wstring bang = LuaManager::ToWide(2);
int top = lua_gettop(L);
if (top == 2) // 1 argument
{
parser.ReplaceVariables(bang);
Rainmeter::GetInstance().ExecuteCommand(bang.c_str(), self);
}
else
{
const WCHAR* bangSz = bang.c_str();
if (*bangSz == L'!')
{
++bangSz; // Skip "!"
std::vector<std::wstring> args;
for (int i = 3; i <= top; ++i)
{
std::wstring tmpSz = LuaManager::ToWide(i);
parser.ReplaceVariables(tmpSz);
args.push_back(tmpSz);
}
Rainmeter::GetInstance().ExecuteBang(bangSz, args, self);
}
}
return 0;
}
static int GetMeter(lua_State* L)
{
DECLARE_SELF(L)
const std::wstring meterName = LuaManager::ToWide(2);
Meter* meter = self->GetMeter(meterName);
if (meter)
{
*(Meter**)lua_newuserdata(L, sizeof(Meter*)) = meter;
lua_getglobal(L, "Meter");
lua_setmetatable(L, -2);
}
else
{
lua_pushnil(L);
}
return 1;
}
static int GetMeasure(lua_State* L)
{
DECLARE_SELF(L)
const std::wstring measureName = LuaManager::ToWide(2);
Measure* measure = self->GetMeasure(measureName);
if (measure)
{
*(Measure**)lua_newuserdata(L, sizeof(Measure*)) = measure;
lua_getglobal(L, "Measure");
lua_setmetatable(L, -2);
}
else
{
lua_pushnil(L);
}
return 1;
}
static int GetVariable(lua_State* L)
{
DECLARE_SELF(L)
const std::wstring name = LuaManager::ToWide(2);
const std::wstring* value = self->GetParser().GetVariable(name);
if (value)
{
LuaManager::PushWide(*value);
}
else if (lua_gettop(L) >= 3)
{
lua_pushvalue(L, 3);
}
else
{
lua_pushnil(L);
}
return 1;
}
static int ReplaceVariables(lua_State* L)
{
DECLARE_SELF(L)
std::wstring strTmp = LuaManager::ToWide(2);
self->GetParser().ReplaceVariables(strTmp);
self->GetParser().ReplaceMeasures(strTmp);
LuaManager::PushWide(strTmp);
return 1;
}
static int ParseFormula(lua_State* L)
{
DECLARE_SELF(L)
std::wstring strTmp = LuaManager::ToWide(2);
double result;
if (!self->GetParser().ParseFormula(strTmp, &result))
{
result = lua_tonumber(L, 2);
}
lua_pushnumber(L, result);
return 1;
}
static int MoveWindow(lua_State* L)
{
DECLARE_SELF(L)
int x = (int)lua_tonumber(L, 2);
int y = (int)lua_tonumber(L, 3);
self->MoveWindow(x, y);
return 0;
}
static int FadeWindow(lua_State* L)
{
DECLARE_SELF(L)
int from = (int)lua_tonumber(L, 2);
int to = (int)lua_tonumber(L, 3);
self->FadeWindow(from, to);
return 0;
}
static int GetW(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetW());
return 1;
}
static int GetH(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetH());
return 1;
}
static int GetX(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetX());
return 1;
}
static int GetY(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetY());
return 1;
}
static int MakePathAbsolute(lua_State* L)
{
DECLARE_SELF(L)
std::wstring path = LuaManager::ToWide(2);
self->MakePathAbsolute(path);
LuaManager::PushWide(path);
return 1;
}
void LuaManager::RegisterMeterWindow(lua_State* L)
{
const luaL_Reg functions[] =
{
{ "Bang", Bang },
{ "GetMeter", GetMeter },
{ "GetMeasure", GetMeasure },
{ "GetVariable", GetVariable },
{ "ReplaceVariables", ReplaceVariables },
{ "ParseFormula", ParseFormula },
{ "MoveWindow", MoveWindow },
{ "FadeWindow", FadeWindow },
{ "GetW", GetW },
{ "GetH", GetH },
{ "GetX", GetX },
{ "GetY", GetY },
{ "MakePathAbsolute", MakePathAbsolute },
{ nullptr, nullptr }
};
luaL_register(L, "MeterWindow", functions);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
lua_pop(L, 1);
}
/*
Copyright (C) 2010 Matt King, Birunthan Mohanathas
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "../LuaManager.h"
#include "../../Rainmeter.h"
#include "../../MeterWindow.h"
#include "../../MeterString.h"
#define DECLARE_SELF(L) \
void* selfData = lua_touserdata(L, 1); \
if (!selfData) return 0; \
MeterWindow* self = *(MeterWindow**)selfData;
static int Bang(lua_State* L)
{
DECLARE_SELF(L)
ConfigParser& parser = self->GetParser();
std::wstring bang = LuaManager::ToWide(2);
int top = lua_gettop(L);
if (top == 2) // 1 argument
{
parser.ReplaceVariables(bang);
Rainmeter::GetInstance().ExecuteCommand(bang.c_str(), self);
}
else
{
const WCHAR* bangSz = bang.c_str();
if (*bangSz == L'!')
{
++bangSz; // Skip "!"
std::vector<std::wstring> args;
for (int i = 3; i <= top; ++i)
{
std::wstring tmpSz = LuaManager::ToWide(i);
parser.ReplaceVariables(tmpSz);
args.push_back(tmpSz);
}
Rainmeter::GetInstance().ExecuteBang(bangSz, args, self);
}
}
return 0;
}
static int GetMeter(lua_State* L)
{
DECLARE_SELF(L)
const std::wstring meterName = LuaManager::ToWide(2);
Meter* meter = self->GetMeter(meterName);
if (meter)
{
*(Meter**)lua_newuserdata(L, sizeof(Meter*)) = meter;
lua_getglobal(L, "Meter");
lua_setmetatable(L, -2);
}
else
{
lua_pushnil(L);
}
return 1;
}
static int GetMeasure(lua_State* L)
{
DECLARE_SELF(L)
const std::wstring measureName = LuaManager::ToWide(2);
Measure* measure = self->GetMeasure(measureName);
if (measure)
{
*(Measure**)lua_newuserdata(L, sizeof(Measure*)) = measure;
lua_getglobal(L, "Measure");
lua_setmetatable(L, -2);
}
else
{
lua_pushnil(L);
}
return 1;
}
static int GetVariable(lua_State* L)
{
DECLARE_SELF(L)
const std::wstring name = LuaManager::ToWide(2);
const std::wstring* value = self->GetParser().GetVariable(name);
if (value)
{
LuaManager::PushWide(*value);
}
else if (lua_gettop(L) >= 3)
{
lua_pushvalue(L, 3);
}
else
{
lua_pushnil(L);
}
return 1;
}
static int ReplaceVariables(lua_State* L)
{
DECLARE_SELF(L)
std::wstring strTmp = LuaManager::ToWide(2);
self->GetParser().ReplaceVariables(strTmp);
self->GetParser().ReplaceMeasures(strTmp);
LuaManager::PushWide(strTmp);
return 1;
}
static int ParseFormula(lua_State* L)
{
DECLARE_SELF(L)
std::wstring strTmp = LuaManager::ToWide(2);
double result;
if (!self->GetParser().ParseFormula(strTmp, &result))
{
result = lua_tonumber(L, 2);
}
lua_pushnumber(L, result);
return 1;
}
static int MoveWindow(lua_State* L)
{
DECLARE_SELF(L)
int x = (int)lua_tonumber(L, 2);
int y = (int)lua_tonumber(L, 3);
self->MoveWindow(x, y);
return 0;
}
static int FadeWindow(lua_State* L)
{
DECLARE_SELF(L)
int from = (int)lua_tonumber(L, 2);
int to = (int)lua_tonumber(L, 3);
self->FadeWindow(from, to);
return 0;
}
static int GetW(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetW());
return 1;
}
static int GetH(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetH());
return 1;
}
static int GetX(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetX());
return 1;
}
static int GetY(lua_State* L)
{
DECLARE_SELF(L)
lua_pushnumber(L, self->GetY());
return 1;
}
static int MakePathAbsolute(lua_State* L)
{
DECLARE_SELF(L)
std::wstring path = LuaManager::ToWide(2);
self->MakePathAbsolute(path);
LuaManager::PushWide(path);
return 1;
}
void LuaManager::RegisterMeterWindow(lua_State* L)
{
const luaL_Reg functions[] =
{
{ "Bang", Bang },
{ "GetMeter", GetMeter },
{ "GetMeasure", GetMeasure },
{ "GetVariable", GetVariable },
{ "ReplaceVariables", ReplaceVariables },
{ "ParseFormula", ParseFormula },
{ "MoveWindow", MoveWindow },
{ "FadeWindow", FadeWindow },
{ "GetW", GetW },
{ "GetH", GetH },
{ "GetX", GetX },
{ "GetY", GetY },
{ "MakePathAbsolute", MakePathAbsolute },
{ nullptr, nullptr }
};
luaL_register(L, "MeterWindow", functions);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
lua_pop(L, 1);
}