update Bytearray to vector use
This commit is contained in:
parent
490727fdc0
commit
22328a9f64
@ -8,7 +8,11 @@ using namespace lua;
|
|||||||
|
|
||||||
|
|
||||||
Bytearray::Bytearray(size_t capacity)
|
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() {
|
Bytearray::~Bytearray() {
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include "lua_commons.hpp"
|
#include "lua_commons.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <vector>
|
||||||
|
|
||||||
namespace lua {
|
namespace lua {
|
||||||
class Userdata {
|
class Userdata {
|
||||||
@ -14,10 +14,10 @@ namespace lua {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Bytearray : public Userdata {
|
class Bytearray : public Userdata {
|
||||||
std::unique_ptr<ubyte[]> buffer;
|
std::vector<ubyte> buffer;
|
||||||
size_t capacity;
|
|
||||||
public:
|
public:
|
||||||
Bytearray(size_t capacity);
|
Bytearray(size_t capacity);
|
||||||
|
Bytearray(std::vector<ubyte> buffer);
|
||||||
virtual ~Bytearray();
|
virtual ~Bytearray();
|
||||||
|
|
||||||
inline ubyte& operator[](size_t index) {
|
inline ubyte& operator[](size_t index) {
|
||||||
@ -29,7 +29,7 @@ namespace lua {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline size_t size() const {
|
inline size_t size() const {
|
||||||
return capacity;
|
return buffer.size();
|
||||||
}
|
}
|
||||||
static int createMetatable(lua::State*);
|
static int createMetatable(lua::State*);
|
||||||
inline static std::string TYPENAME = "bytearray";
|
inline static std::string TYPENAME = "bytearray";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user