mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-12-25 18:20:38 +01:00
Fix crash when loading schematic in a LuaJIT build in recent Minetest versions (thanks LazyJ & VanessaE!).
This commit is contained in:
parent
7f580611f5
commit
04fdf92aca
@ -158,21 +158,23 @@ function worldedit.load_schematic(value)
|
|||||||
-- This is broken for larger tables in the current version of LuaJIT
|
-- This is broken for larger tables in the current version of LuaJIT
|
||||||
nodes = minetest.deserialize(content)
|
nodes = minetest.deserialize(content)
|
||||||
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
|
||||||
nodes = {}
|
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 escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
|
||||||
local startpos, startpos1, endpos = 1, 1
|
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)
|
startpos, endpos = escaped:find("},%s*{", startpos)
|
||||||
if not startpos then
|
if not startpos then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
local current = value:sub(startpos1, startpos)
|
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
|
startpos, startpos1 = endpos, endpos
|
||||||
end
|
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
|
end
|
||||||
else
|
else
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user