@@ -158,21 +158,23 @@ function worldedit.load_schematic(value)
158
158
-- This is broken for larger tables in the current version of LuaJIT
159
159
nodes = minetest .deserialize (content )
160
160
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
162
162
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
164
164
local escaped = value :gsub (" \\\\ " , " @@" ):gsub (" \\\" " , " @@" ):gsub (" (\" [^\" ]*\" )" , function (s ) return string.rep (" @" , # s ) end )
165
165
local startpos , startpos1 , endpos = 1 , 1
166
- while true do
166
+ while true do -- go through each individual node entry (except the last)
167
167
startpos , endpos = escaped :find (" },%s*{" , startpos )
168
168
if not startpos then
169
169
break
170
170
end
171
171
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 )
173
174
startpos , startpos1 = endpos , endpos
174
175
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 )
176
178
end
177
179
else
178
180
return nil
0 commit comments