replace Bytearray with FFI implementation

This commit is contained in:
MihailRis
2025-04-07 20:48:12 +03:00
parent 794aa5b9cd
commit 303e861fbb
16 changed files with 125 additions and 333 deletions
+5 -14
View File
@@ -14,13 +14,10 @@ static int l_tobytes(lua::State* L) {
lua::pushinteger(L, string[i] & 0xFF);
lua::rawseti(L, i+1);
}
return 1;
} else {
lua::newuserdata<lua::LuaBytearray>(L, string.length());
auto bytearray = lua::touserdata<lua::LuaBytearray>(L, -1);
bytearray->data().reserve(string.length());
std::memcpy(bytearray->data().data(), string.data(), string.length());
return lua::create_bytearray(L, string.data(), string.length());
}
return 1;
}
static int l_tostring(lua::State* L) {
@@ -35,16 +32,10 @@ static int l_tostring(lua::State* L) {
}
lua::pop(L);
return lua::pushlstring(L, buffer.data(), size);
} else if (auto bytes = lua::touserdata<lua::LuaBytearray>(L, 1)) {
return lua::pushstring(
L,
std::string(
reinterpret_cast<char*>(bytes->data().data()),
bytes->data().size()
)
);
} else {
lua::bytearray_as_string(L, 1);
return 1;
}
return 1;
}
static int l_length(lua::State* L) {