use Bytearray in lua::pushvalue for byte arrays
This commit is contained in:
@@ -23,6 +23,7 @@ namespace lua {
|
|||||||
public:
|
public:
|
||||||
LuaBytearray(size_t capacity);
|
LuaBytearray(size_t capacity);
|
||||||
LuaBytearray(std::vector<ubyte> buffer);
|
LuaBytearray(std::vector<ubyte> buffer);
|
||||||
|
LuaBytearray(const ubyte* data, size_t size);
|
||||||
virtual ~LuaBytearray();
|
virtual ~LuaBytearray();
|
||||||
|
|
||||||
const std::string& getTypeName() const override {
|
const std::string& getTypeName() const override {
|
||||||
|
|||||||
@@ -60,13 +60,7 @@ int lua::pushvalue(State* L, const dv::value& value) {
|
|||||||
break;
|
break;
|
||||||
case value_type::bytes: {
|
case value_type::bytes: {
|
||||||
const auto& bytes = value.asBytes();
|
const auto& bytes = value.asBytes();
|
||||||
createtable(L, 0, bytes.size());
|
newuserdata<LuaBytearray>(L, bytes.data(), bytes.size());
|
||||||
size_t size = bytes.size();
|
|
||||||
for (size_t i = 0; i < size;) {
|
|
||||||
pushinteger(L, bytes[i]);
|
|
||||||
i++;
|
|
||||||
rawseti(L, i);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ LuaBytearray::LuaBytearray(size_t capacity) : buffer(capacity) {
|
|||||||
LuaBytearray::LuaBytearray(std::vector<ubyte> buffer) : buffer(std::move(buffer)) {
|
LuaBytearray::LuaBytearray(std::vector<ubyte> buffer) : buffer(std::move(buffer)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LuaBytearray::LuaBytearray(const ubyte* data, size_t size) : buffer(data, data + size) {
|
||||||
|
}
|
||||||
|
|
||||||
LuaBytearray::~LuaBytearray() {
|
LuaBytearray::~LuaBytearray() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user