update Bytearray to vector use

This commit is contained in:
MihailRis 2024-06-16 20:40:59 +03:00
parent 490727fdc0
commit 22328a9f64
2 changed files with 9 additions and 5 deletions

View File

@ -8,7 +8,11 @@ using namespace lua;
Bytearray::Bytearray(size_t capacity)
: buffer(std::make_unique<ubyte[]>(capacity)), capacity(capacity) {
: buffer(capacity) {
buffer.resize(capacity);
}
Bytearray::Bytearray(std::vector<ubyte> buffer) : buffer(std::move(buffer)) {
}
Bytearray::~Bytearray() {

View File

@ -4,7 +4,7 @@
#include "lua_commons.hpp"
#include <string>
#include <memory>
#include <vector>
namespace lua {
class Userdata {
@ -14,10 +14,10 @@ namespace lua {
};
class Bytearray : public Userdata {
std::unique_ptr<ubyte[]> buffer;
size_t capacity;
std::vector<ubyte> buffer;
public:
Bytearray(size_t capacity);
Bytearray(std::vector<ubyte> buffer);
virtual ~Bytearray();
inline ubyte& operator[](size_t index) {
@ -29,7 +29,7 @@ namespace lua {
}
inline size_t size() const {
return capacity;
return buffer.size();
}
static int createMetatable(lua::State*);
inline static std::string TYPENAME = "bytearray";