a huge pile of boilerplate code

This commit is contained in:
MihailRis
2024-02-19 14:13:06 +03:00
parent 164d6400d9
commit 7792c1a6f4
5 changed files with 179 additions and 2 deletions
+17
View File
@@ -95,6 +95,23 @@ namespace lua {
lua_pop(L, -1);
return glm::vec2(x, y);
}
inline glm::vec4 tocolor(lua_State* L, int idx) {
lua_pushvalue(L, idx);
if (!lua_istable(L, -1)) {
luaL_error(L, "RGBA array required");
}
lua_rawgeti(L, -1, 1);
lua::luanumber r = lua_tonumber(L, -1); lua_pop(L, -1);
lua_rawgeti(L, -2, 2);
lua::luanumber g = lua_tonumber(L, -1); lua_pop(L, -1);
lua_rawgeti(L, -3, 3);
lua::luanumber b = lua_tonumber(L, -1); lua_pop(L, -1);
lua_rawgeti(L, -4, 4);
lua::luanumber a = lua_tonumber(L, -1); lua_pop(L, -1);
lua_pop(L, -1);
return glm::vec4(r/255, g/255, b/255, a/255);
}
}
#endif // LOGIC_SCRIPTING_LUA_UTIL_H_