From 531e020cbded60c01fbba6536dd7f06b18a2272a Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 20 Nov 2025 12:37:23 +0300 Subject: [PATCH 1/2] add canvas:get_data() -> bytearray --- src/logic/scripting/lua/usertypes/lua_type_canvas.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/logic/scripting/lua/usertypes/lua_type_canvas.cpp b/src/logic/scripting/lua/usertypes/lua_type_canvas.cpp index f89c9d5e..52d4e5e3 100644 --- a/src/logic/scripting/lua/usertypes/lua_type_canvas.cpp +++ b/src/logic/scripting/lua/usertypes/lua_type_canvas.cpp @@ -224,6 +224,13 @@ static int l_set_data(State* L) { return 0; } +static int l_get_data(State* L) { + auto& canvas = require_canvas(L, 1); + auto& image = canvas.getData(); + auto data = image.getData(); + return create_bytearray(L, data, image.getDataSize()); +} + static int l_update(State* L) { if (auto canvas = touserdata(L, 1)) { canvas->update(); @@ -316,6 +323,7 @@ static std::unordered_map methods { {"add", lua::wrap}, {"sub", lua::wrap}, {"encode", lua::wrap}, + {"get_data", lua::wrap}, {"_set_data", lua::wrap}, }; From 49bd33efdb8c1d045c517129a9056ee70d9d98d4 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 20 Nov 2025 12:40:08 +0300 Subject: [PATCH 2/2] update doc/*/scripting/ui.md --- doc/en/scripting/ui.md | 3 ++- doc/ru/scripting/ui.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/en/scripting/ui.md b/doc/en/scripting/ui.md index b58e7e2a..b52460a7 100644 --- a/doc/en/scripting/ui.md +++ b/doc/en/scripting/ui.md @@ -195,7 +195,8 @@ Here, *color* can be specified in the following ways: | data:clear() | clears the canvas | | data:clear(*color*) | fills the canvas with the specified RGBA color | | data:update() | applies changes to the canvas and uploads it to the GPU | -| data:set_data(data: table) | replaces pixel data (width * height * 4 numbers) | +| data:set_data(data: Bytearray | table) | replaces pixel data (width * height * 4 numbers) | +| data:get_data() | creates a Bytearray object with the image's pixel data | | data:create_texture(name: str) | creates and shares texture to renderer | | data:unbind_texture() | unbinds the texture from the canvas | | data:mul(*color* or Canvas) | multiplies a color by the specified color or canvas | diff --git a/doc/ru/scripting/ui.md b/doc/ru/scripting/ui.md index e593dc4a..d5849541 100644 --- a/doc/ru/scripting/ui.md +++ b/doc/ru/scripting/ui.md @@ -195,7 +195,8 @@ document["worlds-panel"]:clear() | data:clear() | очищает холст | | data:clear(*цвет*) | заполняет холст указанным RGBA цветом | | data:update() | применяет изменения и загружает холст в видеопамять | -| data:set_data(data: table) | заменяет данные пикселей (ширина * высота * 4 чисел) | +| data:set_data(data: bytearray | table) | заменяет данные пикселей (ширина * высота * 4 чисел) | +| data:get_data() | создаёт объект Bytearray с пиксельными данными изображения | | data:create_texture(name: str) | создаёт и делится текстурой с рендерером | | data:unbind_texture() | отвязывает текстуру от холста | | data:mul(*цвет* или Canvas) | умножает увет на указанный цвет или холст |