mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 15:01:49 +00:00
add new Bytearray:insert overloads
This commit is contained in:
parent
212cc486d4
commit
d6ccdf9871
1 changed files with 13 additions and 2 deletions
|
|
@ -43,8 +43,19 @@ static int l_insert(lua::State* L) {
|
||||||
if (static_cast<size_t>(index) > data.size()) {
|
if (static_cast<size_t>(index) > data.size()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
auto value = tointeger(L, 3);
|
if (lua::isnumber(L, 3)) {
|
||||||
data.insert(data.begin() + index, static_cast<ubyte>(value));
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue