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
+6 -4
View File
@@ -39,14 +39,16 @@ int l_crc32(lua::State* L) {
string.length()
)
);
} else if (auto bytearray = lua::touserdata<lua::LuaBytearray>(L, 1)) {
auto& bytes = bytearray->data();
return lua::pushinteger(L, crc32(value, bytes.data(), bytes.size()));
} else if (lua::istable(L, 1)) {
std::vector<ubyte> bytes;
lua::read_bytes_from_table(L, 1, bytes);
return lua::pushinteger(L, crc32(value, bytes.data(), bytes.size()));
} else {
throw std::runtime_error("invalid argument 1");
auto string = lua::bytearray_as_string(L, 1);
auto res = crc32(
value, reinterpret_cast<const ubyte*>(string.data()), string.size()
);
lua::pop(L);
return lua::pushinteger(L, res);
}
}