Added love.math.encode(format, data | string [, linelength]) and love.math.decode(format, data | string). Current formats are "base64" and "hex". The optional line length only applies to base64 and specifies the maximum number of characters per line in the encoded string.

Removed the variant of love.filesystem.newFileData which decoded a base64-encoded string since it's redundant.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-03-28 19:28:40 -03:00
parent 9efbe4892c
commit 734789eb93
15 changed files with 394 additions and 141 deletions
+2 -19
View File
@@ -242,26 +242,9 @@ int w_newFileData(lua_State *L)
size_t length = 0;
const char *str = luaL_checklstring(L, 1, &length);
const char *filename = luaL_checkstring(L, 2);
const char *decstr = lua_isstring(L, 3) ? lua_tostring(L, 3) : 0;
FileData::Decoder decoder = FileData::FILE;
if (decstr && !FileData::getConstant(decstr, decoder))
return luaL_error(L, "Invalid FileData decoder: %s", decstr);
FileData *t = 0;
switch (decoder)
{
case FileData::FILE:
t = instance()->newFileData((void *)str, (int)length, filename);
break;
case FileData::BASE64:
t = instance()->newFileData(str, filename);
break;
default:
return luaL_error(L, "Invalid FileData decoder: %s", decstr);
}
FileData *t = nullptr;
luax_catchexcept(L, [&](){ t = instance()->newFileData(str, length, filename); });
luax_pushtype(L, FILESYSTEM_FILE_DATA_ID, t);
t->release();