From d6ccdf98717a9152311f580f128d5e3dbb8710de Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 22 Dec 2024 02:27:00 +0300 Subject: [PATCH] add new Bytearray:insert overloads --- .../lua/usertypes/lua_type_bytearray.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/logic/scripting/lua/usertypes/lua_type_bytearray.cpp b/src/logic/scripting/lua/usertypes/lua_type_bytearray.cpp index c982d2d8..fc7ecf6f 100644 --- a/src/logic/scripting/lua/usertypes/lua_type_bytearray.cpp +++ b/src/logic/scripting/lua/usertypes/lua_type_bytearray.cpp @@ -43,8 +43,19 @@ static int l_insert(lua::State* L) { if (static_cast(index) > data.size()) { return 0; } - auto value = tointeger(L, 3); - data.insert(data.begin() + index, static_cast(value)); + if (lua::isnumber(L, 3)) { + auto value = tointeger(L, 3); + data.insert(data.begin() + index, static_cast(value)); + } else if (lua::istable(L, 3)) { + std::vector temp; + lua::read_bytes_from_table(L, 3, temp); + data.insert(data.begin() + index, temp.begin(), temp.end()); + } else if (auto extension = lua::touserdata(L, 3)) { + const std::vector& src = extension->data(); + data.insert(data.begin() + index, src.begin(), src.end()); + } else { + throw std::runtime_error("integer/table/Bytearray expected"); + } return 0; }