This commit is contained in:
Xertis 2025-10-01 19:01:53 +03:00 committed by GitHub
parent 516e62eade
commit fd8d2c22e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -189,26 +189,48 @@ static int l_list(lua::State* L) {
} }
static int l_gzip_compress(lua::State* L) { static int l_gzip_compress(lua::State* L) {
auto string = lua::bytearray_as_string(L, 1); char argc = lua_gettop(L);
auto str = lua::bytearray_as_string(L, 1);
auto compressedBytes = gzip::compress( auto compressedBytes = gzip::compress(
reinterpret_cast<const ubyte*>(string.data()), reinterpret_cast<const ubyte*>(str.data()),
string.size() str.size()
); );
if (argc < 2 || !lua::toboolean(L, 2)) {
lua::create_bytearray(L, std::move(compressedBytes)); lua::create_bytearray(L, std::move(compressedBytes));
} else {
size_t length = compressedBytes.size();
lua::createtable(L, length, 0);
int newTable = lua::gettop(L);
for (size_t i = 0; i < length; i++) {
lua::pushinteger(L, compressedBytes.data()[i]);
lua::rawseti(L, i + 1, newTable);
}
}
return 1; return 1;
} }
static int l_gzip_decompress(lua::State* L) { static int l_gzip_decompress(lua::State* L) {
auto string = lua::bytearray_as_string(L, 1); char argc = lua_gettop(L);
auto str = lua::bytearray_as_string(L, 1);
auto decompressedBytes = gzip::decompress( auto decompressedBytes = gzip::decompress(
reinterpret_cast<const ubyte*>(string.data()), reinterpret_cast<const ubyte*>(str.data()),
string.size() str.size()
); );
if (argc < 2 || !lua::toboolean(L, 2)) {
lua::create_bytearray(L, std::move(decompressedBytes)); lua::create_bytearray(L, std::move(decompressedBytes));
} else {
size_t length = decompressedBytes.size();
lua::createtable(L, length, 0);
int newTable = lua::gettop(L);
for (size_t i = 0; i < length; i++) {
lua::pushinteger(L, decompressedBytes.data()[i]);
lua::rawseti(L, i + 1, newTable);
}
}
return 1; return 1;
} }