mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-22 15:23:43 +01:00
Make code more robust against corrupt database data
This commit is contained in:
parent
1ded993e4e
commit
c9a013a458
@ -23,16 +23,20 @@ local function deserialize(s)
|
|||||||
local tbl = {}
|
local tbl = {}
|
||||||
for line in s:gmatch("[^;]+") do
|
for line in s:gmatch("[^;]+") do
|
||||||
local num, spos = unpack(string.split(line, "="))
|
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)}
|
tbl[num] = {pos = minetest.string_to_pos(spos)}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
return tbl
|
return tbl
|
||||||
end
|
end
|
||||||
|
|
||||||
local function serialize(data)
|
local function serialize(data)
|
||||||
local tbl = {}
|
local tbl = {}
|
||||||
for k,v in pairs(data) do
|
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)
|
tbl[#tbl+1] = k.."="..minetest.pos_to_string(v.pos)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
return table.concat(tbl, ";")
|
return table.concat(tbl, ";")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user