fix crc32 in static build (#488)

fix crc32 in static build
This commit is contained in:
MihailRis
2025-03-17 20:16:52 +03:00
committed by GitHub
parent 0fefab2cdd
commit 513bac81b5
4 changed files with 31 additions and 19 deletions
+25
View File
@@ -1,4 +1,5 @@
#include <iostream>
#include <zlib.h>
#include "libs/api_lua.hpp"
@@ -25,3 +26,27 @@ int l_print(lua::State* L) {
*output_stream << std::endl;
return 0;
}
int l_crc32(lua::State* L) {
auto value = lua::tointeger(L, 2);
if (lua::isstring(L, 1)) {
auto string = lua::tolstring(L, 1);
return lua::pushinteger(
L,
crc32(
value,
reinterpret_cast<const ubyte*>(string.data()),
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");
}
}