Make code more robust against corrupt database data

This commit is contained in:
Joachim Stolberg 2023-12-27 10:39:52 +01:00
parent 1ded993e4e
commit c9a013a458

@ -23,16 +23,20 @@ local function deserialize(s)
local tbl = {}
for line in s:gmatch("[^;]+") do
local num, spos = unpack(string.split(line, "="))
if num ~= nil and num ~= "" and spos ~= nil and spos ~= "" then
tbl[num] = {pos = minetest.string_to_pos(spos)}
end
end
return tbl
end
local function serialize(data)
local tbl = {}
for k,v in pairs(data) do
if k ~= nil and k ~= "" and v ~= nil and v.pos ~= nil then
tbl[#tbl+1] = k.."="..minetest.pos_to_string(v.pos)
end
end
return table.concat(tbl, ";")
end