From f6dd298e07cc7ded0d2ee1de1b5836304a37c5fd Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 22 Nov 2025 14:40:31 +0300 Subject: [PATCH] add canvas:rect --- .../scripting/lua/usertypes/lua_type_canvas.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/logic/scripting/lua/usertypes/lua_type_canvas.cpp b/src/logic/scripting/lua/usertypes/lua_type_canvas.cpp index 52d4e5e3..54bbf654 100644 --- a/src/logic/scripting/lua/usertypes/lua_type_canvas.cpp +++ b/src/logic/scripting/lua/usertypes/lua_type_canvas.cpp @@ -125,7 +125,9 @@ static RGBA get_rgba(State* L, int first) { rgba.rgba = static_cast(tointeger(L, first)); break; case 3: - rgba.a = static_cast(tointeger(L, first + 3)); + if (lua::isnumber(L, first + 3)) { + rgba.a = static_cast(tointeger(L, first + 3)); + } [[fallthrough]]; case 2: rgba.r = static_cast(tointeger(L, first)); @@ -199,6 +201,18 @@ static int l_blit(State* L) { return 0; } +static int l_rect(State* L) { + auto& canvas = require_canvas(L, 1); + auto& image = canvas.getData(); + int x = tointeger(L, 2); + int y = tointeger(L, 3); + int w = tointeger(L, 4); + int h = tointeger(L, 5); + RGBA rgba = get_rgba(L, 6); + image.drawRect(x, y, w, h, glm::ivec4 {rgba.r, rgba.g, rgba.b, rgba.a}); + return 0; +} + static int l_set_data(State* L) { auto& canvas = require_canvas(L, 1); auto& image = canvas.getData(); @@ -316,6 +330,7 @@ static std::unordered_map methods { {"line", lua::wrap}, {"blit", lua::wrap}, {"clear", lua::wrap}, + {"rect", lua::wrap}, {"update", lua::wrap}, {"create_texture", lua::wrap}, {"unbind_texture", lua::wrap},