-- Table serializer for Mr. Rescue (settings, highscores and stats files). -- Written for this build to replace TSerial.lua, which has no licence text in the -- original repository. Same interface (TSerial.pack / TSerial.unpack); released -- under the zlib licence, like the rest of the game's code. TSerial = {} local function ser(v, out) local tv = type(v) if tv == "number" then out[#out+1] = string.format("%.17g", v) elseif tv == "string" then out[#out+1] = string.format("%q", v) elseif tv == "boolean" then out[#out+1] = v and "true" or "false" elseif tv == "table" then out[#out+1] = "{" for k, x in pairs(v) do out[#out+1] = "[" ser(k, out) out[#out+1] = "]=" ser(x, out) out[#out+1] = "," end out[#out+1] = "}" else error("TSerial: cannot serialize a " .. tv) end end function TSerial.pack(t) assert(type(t) == "table", "Can only TSerial.pack tables.") local out = {} ser(t, out) return table.concat(out) end function TSerial.unpack(s) assert(type(s) == "string", "Can only TSerial.unpack strings.") local f = assert(loadstring("return " .. s)) setfenv(f, {}) return f() end