1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2024-12-24 17:50:40 +01:00

Log deserialization errors

This commit is contained in:
sfan5 2023-06-07 11:50:33 +02:00
parent 7a645eba05
commit 5260f595c6

View File

@ -115,14 +115,14 @@ function worldedit.serialize(pos1, pos2)
end end
local function deserialize_workaround(content) local function deserialize_workaround(content)
local nodes local nodes, err
if not minetest.global_exists("jit") then if not minetest.global_exists("jit") then
nodes = minetest.deserialize(content, true) nodes, err = minetest.deserialize(content, true)
elseif not content:match("^%s*return%s*{") then elseif not content:match("^%s*return%s*{") then
-- The data doesn't look like we expect it to so we can't apply the workaround. -- The data doesn't look like we expect it to so we can't apply the workaround.
-- hope for the best -- hope for the best
minetest.log("warning", "WorldEdit: deserializing data but can't apply LuaJIT workaround") minetest.log("warning", "WorldEdit: deserializing data but can't apply LuaJIT workaround")
nodes = minetest.deserialize(content, true) nodes, err = minetest.deserialize(content, true)
else else
-- XXX: This is a filthy hack that works surprisingly well -- XXX: This is a filthy hack that works surprisingly well
-- in LuaJIT, `minetest.deserialize` will fail due to the register limit -- in LuaJIT, `minetest.deserialize` will fail due to the register limit
@ -132,18 +132,27 @@ local function deserialize_workaround(content)
local escaped = content:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end) local escaped = content:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
local startpos, startpos1 = 1, 1 local startpos, startpos1 = 1, 1
local endpos local endpos
local entry
while true do -- go through each individual node entry (except the last) while true do -- go through each individual node entry (except the last)
startpos, endpos = escaped:find("}%s*,%s*{", startpos) startpos, endpos = escaped:find("}%s*,%s*{", startpos)
if not startpos then if not startpos then
break break
end end
local current = content:sub(startpos1, startpos) local current = content:sub(startpos1, startpos)
local entry = minetest.deserialize("return " .. current, true) entry, err = minetest.deserialize("return " .. current, true)
if not entry then
break
end
table.insert(nodes, entry) table.insert(nodes, entry)
startpos, startpos1 = endpos, endpos startpos, startpos1 = endpos, endpos
end end
local entry = minetest.deserialize("return " .. content:sub(startpos1), true) -- process the last entry if not err then
table.insert(nodes, entry) entry = minetest.deserialize("return " .. content:sub(startpos1), true) -- process the last entry
table.insert(nodes, entry)
end
end
if err then
minetest.log("warning", "WorldEdit: deserialize: " .. err)
end end
return nodes return nodes
end end