mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Added a new variant love.math.decompress(data, format), where data is any Data object.
This commit is contained in:
@@ -358,7 +358,7 @@ int w_compress(lua_State *L)
|
||||
Compressor::Format format = Compressor::FORMAT_LZ4;
|
||||
|
||||
if (fstr && !Compressor::getConstant(fstr, format))
|
||||
return luaL_error(L, "Invalid compressed format: %s", fstr);
|
||||
return luaL_error(L, "Invalid compressed data format: %s", fstr);
|
||||
|
||||
int level = (int) luaL_optnumber(L, 3, -1);
|
||||
|
||||
@@ -384,25 +384,34 @@ int w_decompress(lua_State *L)
|
||||
char *rawbytes = nullptr;
|
||||
size_t rawsize = 0;
|
||||
|
||||
if (lua_isstring(L, 1))
|
||||
if (luax_istype(L, 1, MATH_COMPRESSED_DATA_ID))
|
||||
{
|
||||
CompressedData *data = luax_checkcompresseddata(L, 1);
|
||||
rawsize = data->getDecompressedSize();
|
||||
luax_catchexcept(L, [&](){ rawbytes = Math::instance.decompress(data, rawsize); });
|
||||
}
|
||||
else
|
||||
{
|
||||
Compressor::Format format = Compressor::FORMAT_LZ4;
|
||||
const char *fstr = luaL_checkstring(L, 2);
|
||||
|
||||
if (!Compressor::getConstant(fstr, format))
|
||||
return luaL_error(L, "Invalid compressed format: %s", fstr);
|
||||
return luaL_error(L, "Invalid compressed data format: %s", fstr);
|
||||
|
||||
size_t compressedsize = 0;
|
||||
const char *cbytes = luaL_checklstring(L, 1, &compressedsize);
|
||||
const char *cbytes = nullptr;
|
||||
|
||||
if (luax_istype(L, 1, DATA_ID))
|
||||
{
|
||||
Data *data = luax_checktype<Data>(L, 1, DATA_ID);
|
||||
cbytes = (const char *) data->getData();
|
||||
compressedsize = data->getSize();
|
||||
}
|
||||
else
|
||||
cbytes = luaL_checklstring(L, 1, &compressedsize);
|
||||
|
||||
luax_catchexcept(L, [&](){ rawbytes = Math::instance.decompress(format, cbytes, compressedsize, rawsize); });
|
||||
}
|
||||
else
|
||||
{
|
||||
CompressedData *data = luax_checkcompresseddata(L, 1);
|
||||
rawsize = data->getDecompressedSize();
|
||||
luax_catchexcept(L, [&](){ rawbytes = Math::instance.decompress(data, rawsize); });
|
||||
}
|
||||
|
||||
lua_pushlstring(L, rawbytes, rawsize);
|
||||
delete[] rawbytes;
|
||||
|
||||
Reference in New Issue
Block a user