I tried couple of the lua serializing tools to serialize my object: https://github.com/gvx/Smallfolk and smallfolk failed to deserialize on "exp" = 0, it didn't like 0 as a number.
Second one I tried was https://love2d.org/wiki/Tserialwhich for some reason couldn't deserialize the stuff it serialized.
The third one I tried actually works just fine, but it returns unsafe lua-file: https://github.com/gvx/Ser
Basically the output is something as following in ser, where it just has a huge list of characters and their stats:
Code: Select all
_[36] = {"0", "300000"}
_[17] = {classType = "Ranger", important = true, expGain = 50, alias = "Peter", npc = false, spi = 77, vit = 155, lvl = 101, str = 112, skills = _[36], img = "8", int = 99, exp = 0, luc = 146, speed = 5, name = "Peter", dex = 230}
_[1] = {["4"] = _[2], test2 = _[3], ["5"] = _[4], test7 = _[5], test4 = _[6], test9 = _[7], test6 = _[8], ["7"] = _[9], test8 = _[10], ["1"] = _[11], ["6"] = _[12], test1 = _[13], test5 = _[14], ["3"] = _[15], test3 = _[16], ["2"] = _[17], test10 = _[18], test12 = _[19], test11 = _[20]}
return {units = _[1]}
So the way I am actually loading is by using loadstring, which could do a lot of unwanted stuff. So I was thinking if I run something like:
Code: Select all
local brackets = serString:find("[()]")
if not brackets then
local f = assert(loadstring( serString ))
local saveState = f()
... do my stuff
end
I am able to accept that the game crashes if the savefile is incorrect, but not stuff like delete files from harddrive by modifying the save file etc. Also since I am kinda trying to get this working in android at the same time, I think that I should be a bit more caution about these things.