mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Several love.data functions now take an enum ("data" or "string") to determine whether they return a Data object or a string.
Changed functions are love.data.compress, decompress, encode, decode, and pack.
This commit is contained in:
@@ -360,20 +360,21 @@ int w_compress(lua_State *L)
|
||||
return luax_enumerror(L, "compressed data format", Compressor::getConstants(format), fstr);
|
||||
|
||||
int level = (int) luaL_optinteger(L, 3, -1);
|
||||
size_t rawsize = 0;
|
||||
const char *rawbytes = nullptr;
|
||||
|
||||
CompressedData *cdata = nullptr;
|
||||
if (lua_isstring(L, 1))
|
||||
{
|
||||
size_t rawsize = 0;
|
||||
const char *rawbytes = luaL_checklstring(L, 1, &rawsize);
|
||||
luax_catchexcept(L, [&](){ cdata = compress(format, rawbytes, rawsize, level); });
|
||||
}
|
||||
rawbytes = luaL_checklstring(L, 1, &rawsize);
|
||||
else
|
||||
{
|
||||
Data *rawdata = luax_checktype<Data>(L, 1);
|
||||
luax_catchexcept(L, [&](){ cdata = compress(format, rawdata, level); });
|
||||
rawsize = rawdata->getSize();
|
||||
rawbytes = (const char *) rawdata->getData();
|
||||
}
|
||||
|
||||
CompressedData *cdata = nullptr;
|
||||
luax_catchexcept(L, [&](){ cdata = compress(format, rawbytes, rawsize, level); });
|
||||
|
||||
luax_pushtype(L, cdata);
|
||||
cdata->release();
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user