Skip to content

Commit

Permalink
add new Bytearray:insert overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Dec 21, 2024
1 parent 212cc48 commit d6ccdf9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/logic/scripting/lua/usertypes/lua_type_bytearray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,19 @@ static int l_insert(lua::State* L) {
if (static_cast<size_t>(index) > data.size()) {
return 0;
}
auto value = tointeger(L, 3);
data.insert(data.begin() + index, static_cast<ubyte>(value));
if (lua::isnumber(L, 3)) {
auto value = tointeger(L, 3);
data.insert(data.begin() + index, static_cast<ubyte>(value));
} else if (lua::istable(L, 3)) {
std::vector<ubyte> temp;
lua::read_bytes_from_table(L, 3, temp);
data.insert(data.begin() + index, temp.begin(), temp.end());
} else if (auto extension = lua::touserdata<LuaBytearray>(L, 3)) {
const std::vector<ubyte>& src = extension->data();
data.insert(data.begin() + index, src.begin(), src.end());
} else {
throw std::runtime_error("integer/table/Bytearray expected");
}
return 0;
}

Expand Down

0 comments on commit d6ccdf9

Please sign in to comment.