MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / Register

Method Register

LuaSTGPlus/LuaWrapper.cpp:92–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90////////////////////////////////////////////////////////////////////////////////
91#pragma region ColorWrapper
92void ColorWrapper::Register(lua_State* L)LNOEXCEPT
93{
94 struct WrapperImplement
95 {
96 static int ARGB(lua_State* L)LNOEXCEPT
97 {
98 fcyColor* p = static_cast<fcyColor*>(luaL_checkudata(L, 1, TYPENAME_COLOR));
99 lua_pushnumber(L, p->a);
100 lua_pushnumber(L, p->r);
101 lua_pushnumber(L, p->g);
102 lua_pushnumber(L, p->b);
103 return 4;
104 }
105 static int Meta_Eq(lua_State* L)LNOEXCEPT
106 {
107 fcyColor* pA = static_cast<fcyColor*>(luaL_checkudata(L, 1, TYPENAME_COLOR));
108 fcyColor* pB = static_cast<fcyColor*>(luaL_checkudata(L, 2, TYPENAME_COLOR));
109 lua_pushboolean(L, pA->argb == pB->argb);
110 return 1;
111 }
112 static int Meta_Add(lua_State* L)LNOEXCEPT
113 {
114 fcyColor* pA = static_cast<fcyColor*>(luaL_checkudata(L, 1, TYPENAME_COLOR));
115 fcyColor* pB = static_cast<fcyColor*>(luaL_checkudata(L, 2, TYPENAME_COLOR));
116 fcyColor* pResult = CreateAndPush(L);
117 pResult->Set(
118 ::min((int)pA->a + pB->a, 255),
119 ::min((int)pA->r + pB->r, 255),
120 ::min((int)pA->g + pB->g, 255),
121 ::min((int)pA->b + pB->b, 255)
122 );
123 return 1;
124 }
125 static int Meta_Sub(lua_State* L)LNOEXCEPT
126 {
127 fcyColor* pA = static_cast<fcyColor*>(luaL_checkudata(L, 1, TYPENAME_COLOR));
128 fcyColor* pB = static_cast<fcyColor*>(luaL_checkudata(L, 2, TYPENAME_COLOR));
129 fcyColor* pResult = CreateAndPush(L);
130 pResult->Set(
131 ::max((int)pA->a - pB->a, 0),
132 ::max((int)pA->r - pB->r, 0),
133 ::max((int)pA->g - pB->g, 0),
134 ::max((int)pA->b - pB->b, 0)
135 );
136 return 1;
137 }
138 static int Meta_Mul(lua_State* L)LNOEXCEPT
139 {
140 lua_Number tFactor;
141 fcyColor *p = nullptr, *pResult = nullptr;
142 if (lua_isnumber(L, 1)) // arg1为数字,则arg2必为lstgColor
143 {
144 tFactor = luaL_checknumber(L, 1);
145 p = static_cast<fcyColor*>(luaL_checkudata(L, 2, TYPENAME_COLOR));
146 }
147 else if (lua_isnumber(L, 2)) // arg2为数字,则arg1必为lstgColor
148 {
149 tFactor = luaL_checknumber(L, 2);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected