add new Bytearray:append overloads
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <typeindex>
|
||||
#include <typeinfo>
|
||||
#include <stdexcept>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "data/dv.hpp"
|
||||
@@ -698,4 +699,25 @@ namespace lua {
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
inline void read_bytes_from_table(
|
||||
lua::State* L, int tableIndex, std::vector<ubyte>& bytes
|
||||
) {
|
||||
if (!lua::istable(L, tableIndex)) {
|
||||
throw std::runtime_error("table expected");
|
||||
} else {
|
||||
size_t size = lua::objlen(L, tableIndex);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
lua::rawgeti(L, i + 1, tableIndex);
|
||||
const int byte = lua::tointeger(L, -1);
|
||||
lua::pop(L);
|
||||
if (byte < 0 || byte > 255) {
|
||||
throw std::runtime_error(
|
||||
"invalid byte '" + std::to_string(byte) + "'"
|
||||
);
|
||||
}
|
||||
bytes.push_back(byte);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user