Skip to content

Commit 04fdf92

Browse files
committedDec 29, 2014
Fix crash when loading schematic in a LuaJIT build in recent Minetest versions (thanks LazyJ & VanessaE!).
1 parent 7f58061 commit 04fdf92

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
 

‎worldedit/serialization.lua

+7-5
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,23 @@ function worldedit.load_schematic(value)
158158
-- This is broken for larger tables in the current version of LuaJIT
159159
nodes = minetest.deserialize(content)
160160
else
161-
-- XXX: This is a filthy hack that works surprisingly well
161+
-- XXX: This is a filthy hack that works surprisingly well - in LuaJIT, `minetest.deserialize` will fail due to the register limit
162162
nodes = {}
163-
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
163+
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1) -- remove the starting and ending values to leave only the node data
164164
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
165165
local startpos, startpos1, endpos = 1, 1
166-
while true do
166+
while true do -- go through each individual node entry (except the last)
167167
startpos, endpos = escaped:find("},%s*{", startpos)
168168
if not startpos then
169169
break
170170
end
171171
local current = value:sub(startpos1, startpos)
172-
table.insert(nodes, minetest.deserialize("return " .. current))
172+
local entry = minetest.deserialize("return " .. current)
173+
table.insert(nodes, entry)
173174
startpos, startpos1 = endpos, endpos
174175
end
175-
table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))
176+
local entry = minetest.deserialize("return " .. value:sub(startpos1)) -- process the last entry
177+
table.insert(nodes, entry)
176178
end
177179
else
178180
return nil

0 commit comments

Comments
 (0)
Please sign in to comment.