diff options
author | Anthony Zhang <azhang9@gmail.com> | 2014-12-29 18:26:37 -0500 |
---|---|---|
committer | Anthony Zhang <azhang9@gmail.com> | 2014-12-29 18:26:37 -0500 |
commit | 04fdf92aca66641de87a6e7d00de2bdd796858d1 (patch) | |
tree | 3aeb25bdecccba303d9442b5b4fc3bc40c910aef /worldedit | |
parent | 7f580611f564bc4d67c3b77fc4866b4afb2fb98a (diff) |
Fix crash when loading schematic in a LuaJIT build in recent Minetest versions (thanks LazyJ & VanessaE!).
Diffstat (limited to 'worldedit')
-rw-r--r-- | worldedit/serialization.lua | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/worldedit/serialization.lua b/worldedit/serialization.lua index 86b23ec..f129168 100644 --- a/worldedit/serialization.lua +++ b/worldedit/serialization.lua @@ -158,21 +158,23 @@ function worldedit.load_schematic(value) -- This is broken for larger tables in the current version of LuaJIT
nodes = minetest.deserialize(content)
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
nodes = {}
- value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
+ value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1) -- remove the starting and ending values to leave only the node data
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
local startpos, startpos1, endpos = 1, 1
- while true do
+ while true do -- go through each individual node entry (except the last)
startpos, endpos = escaped:find("},%s*{", startpos)
if not startpos then
break
end
local current = value:sub(startpos1, startpos)
- table.insert(nodes, minetest.deserialize("return " .. current))
+ local entry = minetest.deserialize("return " .. current)
+ table.insert(nodes, entry)
startpos, startpos1 = endpos, endpos
end
- table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))
+ local entry = minetest.deserialize("return " .. value:sub(startpos1)) -- process the last entry
+ table.insert(nodes, entry)
end
else
return nil
|