diff --git a/Library/lua/glue/LuaMeasure.cpp b/Library/lua/glue/LuaMeasure.cpp index bcebc37e..42f6f267 100644 --- a/Library/lua/glue/LuaMeasure.cpp +++ b/Library/lua/glue/LuaMeasure.cpp @@ -21,14 +21,14 @@ #include "../../Measure.h" #include "../../MeterWindow.h" -inline CMeasure* GetSelf(lua_State* L) -{ - return *(CMeasure**)lua_touserdata(L, 1); -} +#define DECLARE_SELF(L) \ + void* selfData = lua_touserdata(L, 1); \ + if (!selfData) return 0; \ + CMeasure* self = *(CMeasure**)selfData; static int GetName(lua_State* L) { - CMeasure* self = GetSelf(L); + DECLARE_SELF(L) LuaManager::PushWide(L, self->GetName()); return 1; @@ -36,7 +36,7 @@ static int GetName(lua_State* L) static int GetOption(lua_State* L) { - CMeasure* self = GetSelf(L); + DECLARE_SELF(L) CMeterWindow* meterWindow = self->GetMeterWindow(); CConfigParser& parser = meterWindow->GetParser(); @@ -49,7 +49,7 @@ static int GetOption(lua_State* L) static int GetNumberOption(lua_State* L) { - CMeasure* self = GetSelf(L); + DECLARE_SELF(L) CMeterWindow* meterWindow = self->GetMeterWindow(); CConfigParser& parser = meterWindow->GetParser(); @@ -62,7 +62,7 @@ static int GetNumberOption(lua_State* L) static int Disable(lua_State* L) { - CMeasure* self = GetSelf(L); + DECLARE_SELF(L) self->Disable(); return 0; @@ -70,7 +70,7 @@ static int Disable(lua_State* L) static int Enable(lua_State* L) { - CMeasure* self = GetSelf(L); + DECLARE_SELF(L) self->Enable(); return 0; @@ -78,7 +78,7 @@ static int Enable(lua_State* L) static int GetValue(lua_State* L) { - CMeasure* self = GetSelf(L); + DECLARE_SELF(L) lua_pushnumber(L, self->GetValue()); return 1; @@ -86,7 +86,7 @@ static int GetValue(lua_State* L) static int GetRelativeValue(lua_State* L) { - CMeasure* self = GetSelf(L); + DECLARE_SELF(L) lua_pushnumber(L, self->GetRelativeValue()); return 1; @@ -94,7 +94,7 @@ static int GetRelativeValue(lua_State* L) static int GetValueRange(lua_State* L) { - CMeasure* self = GetSelf(L); + DECLARE_SELF(L) lua_pushnumber(L, self->GetValueRange()); return 1; @@ -102,7 +102,7 @@ static int GetValueRange(lua_State* L) static int GetMinValue(lua_State* L) { - CMeasure* self = GetSelf(L); + DECLARE_SELF(L) lua_pushnumber(L, self->GetMinValue()); return 1; @@ -110,7 +110,7 @@ static int GetMinValue(lua_State* L) static int GetMaxValue(lua_State* L) { - CMeasure* self = GetSelf(L); + DECLARE_SELF(L) lua_pushnumber(L, self->GetMaxValue()); return 1; @@ -118,7 +118,7 @@ static int GetMaxValue(lua_State* L) static int GetStringValue(lua_State* L) { - CMeasure* self = GetSelf(L); + DECLARE_SELF(L) int top = lua_gettop(L); AUTOSCALE autoScale = (top > 1) ? (AUTOSCALE)(int)lua_tonumber(L, 2) : AUTOSCALE_OFF; diff --git a/Library/lua/glue/LuaMeter.cpp b/Library/lua/glue/LuaMeter.cpp index dd7d0e8b..ba4a3877 100644 --- a/Library/lua/glue/LuaMeter.cpp +++ b/Library/lua/glue/LuaMeter.cpp @@ -21,14 +21,14 @@ #include "../../Meter.h" #include "../../MeterString.h" -inline CMeter* GetSelf(lua_State* L) -{ - return *(CMeter**)lua_touserdata(L, 1); -} +#define DECLARE_SELF(L) \ + void* selfData = lua_touserdata(L, 1); \ + if (!selfData) return 0; \ + CMeter* self = *(CMeter**)selfData; static int GetName(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) LuaManager::PushWide(L, self->GetName()); return 1; @@ -36,7 +36,7 @@ static int GetName(lua_State* L) static int GetOption(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) CMeterWindow* meterWindow = self->GetMeterWindow(); CConfigParser& parser = meterWindow->GetParser(); @@ -49,7 +49,7 @@ static int GetOption(lua_State* L) static int GetW(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) lua_pushnumber(L, self->GetW()); return 1; @@ -57,7 +57,7 @@ static int GetW(lua_State* L) static int GetH(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) lua_pushnumber(L, self->GetH()); return 1; @@ -66,7 +66,7 @@ static int GetH(lua_State* L) static int GetX(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) bool abs = (bool)lua_toboolean(L, 2); lua_pushnumber(L, self->GetX(abs)); @@ -75,7 +75,7 @@ static int GetX(lua_State* L) static int GetY(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) bool abs = (bool)lua_toboolean(L, 2); lua_pushnumber(L, self->GetY(abs)); @@ -84,7 +84,7 @@ static int GetY(lua_State* L) static int SetW(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) int w = (int)lua_tonumber(L, 2); self->SetW(w); @@ -93,7 +93,7 @@ static int SetW(lua_State* L) static int SetH(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) int h = (int)lua_tonumber(L, 2); self->SetH(h); @@ -102,7 +102,7 @@ static int SetH(lua_State* L) static int SetX(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) int x = (int)lua_tonumber(L, 2); self->SetX(x); @@ -111,7 +111,7 @@ static int SetX(lua_State* L) static int SetY(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) int y = (int)lua_tonumber(L, 2); self->SetY(y); @@ -120,7 +120,7 @@ static int SetY(lua_State* L) static int Hide(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) self->Hide(); return 0; @@ -128,7 +128,7 @@ static int Hide(lua_State* L) static int Show(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) self->Show(); return 0; @@ -136,7 +136,7 @@ static int Show(lua_State* L) static int SetText(lua_State* L) { - CMeter* self = GetSelf(L); + DECLARE_SELF(L) if (self->GetTypeID() == TypeID()) { CMeterString* string = (CMeterString*)self; diff --git a/Library/lua/glue/LuaMeterWindow.cpp b/Library/lua/glue/LuaMeterWindow.cpp index c892a31e..bc1fb63f 100644 --- a/Library/lua/glue/LuaMeterWindow.cpp +++ b/Library/lua/glue/LuaMeterWindow.cpp @@ -24,14 +24,14 @@ extern CRainmeter* Rainmeter; -inline CMeterWindow* GetSelf(lua_State* L) -{ - return *(CMeterWindow**)lua_touserdata(L, 1); -} +#define DECLARE_SELF(L) \ + void* selfData = lua_touserdata(L, 1); \ + if (!selfData) return 0; \ + CMeterWindow* self = *(CMeterWindow**)selfData; static int Bang(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) CConfigParser& parser = self->GetParser(); std::wstring bang = LuaManager::ToWide(L, 2); @@ -65,7 +65,7 @@ static int Bang(lua_State* L) static int GetMeter(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) const std::wstring meterName = LuaManager::ToWide(L, 2); CMeter* meter = self->GetMeter(meterName); @@ -85,7 +85,7 @@ static int GetMeter(lua_State* L) static int GetMeasure(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) const std::wstring measureName = LuaManager::ToWide(L, 2); CMeasure* measure = self->GetMeasure(measureName); @@ -105,7 +105,7 @@ static int GetMeasure(lua_State* L) static int GetVariable(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) std::wstring strTmp = LuaManager::ToWide(L, 2); const std::wstring* value = self->GetParser().GetVariable(strTmp); @@ -123,7 +123,7 @@ static int GetVariable(lua_State* L) static int ReplaceVariables(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) std::wstring strTmp = LuaManager::ToWide(L, 2); self->GetParser().ReplaceVariables(strTmp); @@ -135,7 +135,7 @@ static int ReplaceVariables(lua_State* L) static int ParseFormula(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) std::wstring strTmp = LuaManager::ToWide(L, 2); double result; @@ -151,7 +151,7 @@ static int ParseFormula(lua_State* L) static int MoveWindow(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) int x = (int)lua_tonumber(L, 2); int y = (int)lua_tonumber(L, 3); self->MoveWindow(x, y); @@ -161,7 +161,7 @@ static int MoveWindow(lua_State* L) static int FadeWindow(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) int from = (int)lua_tonumber(L, 2); int to = (int)lua_tonumber(L, 3); self->FadeWindow(from, to); @@ -171,7 +171,7 @@ static int FadeWindow(lua_State* L) static int GetW(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) lua_pushnumber(L, self->GetW()); return 1; @@ -179,7 +179,7 @@ static int GetW(lua_State* L) static int GetH(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) lua_pushnumber(L, self->GetH()); return 1; @@ -187,7 +187,7 @@ static int GetH(lua_State* L) static int GetX(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) lua_pushnumber(L, self->GetX()); return 1; @@ -195,7 +195,7 @@ static int GetX(lua_State* L) static int GetY(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) lua_pushnumber(L, self->GetY()); return 1; @@ -203,7 +203,7 @@ static int GetY(lua_State* L) static int MakePathAbsolute(lua_State* L) { - CMeterWindow* self = GetSelf(L); + DECLARE_SELF(L) std::wstring path = LuaManager::ToWide(L, 2); self->MakePathAbsolute(path); LuaManager::PushWide(L, path.c_str());