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:
Alex Szpakowski
2017-12-22 16:13:20 -04:00
parent 9bae1f01ba
commit 9fa73f8b87
9 changed files with 455 additions and 386 deletions
+8 -7
View File
@@ -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;