add canvas:sub method

This commit is contained in:
MihailRis
2025-11-11 19:34:40 +03:00
parent 83f7bf80c4
commit 34d13442b6
5 changed files with 25 additions and 8 deletions
@@ -261,9 +261,23 @@ static int l_add(State* L) {
}
if (lua::istable(L, 2)) {
RGBA rgba = get_rgba(L, 2);
canvas->getData().addColor(glm::ivec4 {rgba.r, rgba.g, rgba.b, rgba.a});
canvas->getData().addColor(glm::ivec4 {rgba.r, rgba.g, rgba.b, rgba.a}, 1);
} else if (auto other = touserdata<LuaCanvas>(L, 2)) {
canvas->getData().addColor(other->getData());
canvas->getData().addColor(other->getData(), 1);
}
return 0;
}
static int l_sub(State* L) {
auto canvas = touserdata<LuaCanvas>(L, 1);
if (canvas == nullptr) {
return 0;
}
if (lua::istable(L, 2)) {
RGBA rgba = get_rgba(L, 2);
canvas->getData().addColor(glm::ivec4 {rgba.r, rgba.g, rgba.b, rgba.a}, -1);
} else if (auto other = touserdata<LuaCanvas>(L, 2)) {
canvas->getData().addColor(other->getData(), -1);
}
return 0;
}
@@ -279,6 +293,7 @@ static std::unordered_map<std::string, lua_CFunction> methods {
{"unbind_texture", lua::wrap<l_unbind_texture>},
{"mul", lua::wrap<l_mul>},
{"add", lua::wrap<l_add>},
{"sub", lua::wrap<l_sub>},
{"_set_data", lua::wrap<l_set_data>},
};