]> git.lizzy.rs Git - worldedit.git/commitdiff
Fix deserialization of schematics with node names table master
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Mon, 27 Mar 2023 13:43:09 +0000 (15:43 +0200)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Mon, 27 Mar 2023 13:43:09 +0000 (15:43 +0200)
worldedit/serialization.lua

index 4140e171f496e5dec2d262dc5d5fdd04e9ff64f8..86141c4dd6ea046b2839a9deb0f9deb9e9f89a6d 100644 (file)
@@ -118,7 +118,7 @@ local function deserialize_workaround(content)
        local nodes\r
        if not minetest.global_exists("jit") then\r
                nodes = minetest.deserialize(content, true)\r
-       elseif not content:match("^%s*return%s*{") then\r
+       elseif not content:find("return%s*{") then\r
                -- The data doesn't look like we expect it to so we can't apply the workaround.\r
                -- hope for the best\r
                minetest.log("warning", "WorldEdit: deserializing data but can't apply LuaJIT workaround")\r
@@ -127,7 +127,11 @@ local function deserialize_workaround(content)
                -- XXX: This is a filthy hack that works surprisingly well\r
                -- in LuaJIT, `minetest.deserialize` will fail due to the register limit\r
                nodes = {}\r
-               content = content:gsub("^%s*return%s*{", "", 1):gsub("}%s*$", "", 1) -- remove the starting and ending values to leave only the node data\r
+\r
+               local startreturn, endreturn = content:find("return%s*{")\r
+               local header = content:sub(1, startreturn-1)\r
+\r
+               content = content:sub(endreturn+1):gsub("}%s*$", "", 1) -- remove the starting and ending values to leave only the node data\r
                -- remove string contents strings while preserving their length\r
                local escaped = content:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)\r
                local startpos, startpos1 = 1, 1\r
@@ -138,7 +142,7 @@ local function deserialize_workaround(content)
                                break\r
                        end\r
                        local current = content:sub(startpos1, startpos)\r
-                       local entry = minetest.deserialize("return " .. current, true)\r
+                       local entry = minetest.deserialize(header .. " return " .. current, true)\r
                        table.insert(nodes, entry)\r
                        startpos, startpos1 = endpos, endpos\r
                end\r