]> git.lizzy.rs Git - worldedit.git/commitdiff
Fix crash when loading schematic in a LuaJIT build in recent Minetest versions (thank...
authorAnthony Zhang <azhang9@gmail.com>
Mon, 29 Dec 2014 23:26:37 +0000 (18:26 -0500)
committerAnthony Zhang <azhang9@gmail.com>
Mon, 29 Dec 2014 23:26:37 +0000 (18:26 -0500)
worldedit/serialization.lua

index 86b23ec60bc3fb766d75396a7843f1e18deeed4a..f129168a35ee2be9ff8411d6c73730b47442d4bf 100644 (file)
@@ -158,21 +158,23 @@ function worldedit.load_schematic(value)
                        -- This is broken for larger tables in the current version of LuaJIT\r
                        nodes = minetest.deserialize(content)\r
                else\r
-                       -- XXX: This is a filthy hack that works surprisingly well\r
+                       -- XXX: This is a filthy hack that works surprisingly well - in LuaJIT, `minetest.deserialize` will fail due to the register limit\r
                        nodes = {}\r
-                       value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)\r
+                       value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1) -- remove the starting and ending values to leave only the node data\r
                        local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)\r
                        local startpos, startpos1, endpos = 1, 1\r
-                       while true do\r
+                       while true do -- go through each individual node entry (except the last)\r
                                startpos, endpos = escaped:find("},%s*{", startpos)\r
                                if not startpos then\r
                                        break\r
                                end\r
                                local current = value:sub(startpos1, startpos)\r
-                               table.insert(nodes, minetest.deserialize("return " .. current))\r
+                               local entry = minetest.deserialize("return " .. current)\r
+                               table.insert(nodes, entry)\r
                                startpos, startpos1 = endpos, endpos\r
                        end\r
-                       table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))\r
+                       local entry = minetest.deserialize("return " .. value:sub(startpos1)) -- process the last entry\r
+                       table.insert(nodes, entry)\r
                end\r
        else\r
                return nil\r