- --load the node array\r
- count = #nodes\r
- if version == 1 then --original flat table format\r
- for index = 1, count do\r
- local entry = nodes[index]\r
- local pos = entry[1]\r
- pos.x, pos.y, pos.z = originx - pos.x, originy - pos.y, originz - pos.z\r
- add_node(pos, entry[2])\r
- end\r
- else --previous meta flat table format\r
- for index = 1, #nodes do\r
- local entry = nodes[index]\r
- entry.x, entry.y, entry.z = originx + entry.x, originy + entry.y, originz + entry.z\r
- add_node(entry, entry) --entry acts both as position and as node\r
- get_meta(entry):from_table(entry.meta)\r
- end\r
- end\r
- elseif version == 3 then --previous list format\r
- local pos = {x=0, y=0, z=0}\r
- local node = {name="", param1=0, param2=0}\r
- for x, y, z, name, param1, param2 in value:gmatch("([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)%s+([^%s]+)%s+(%d+)%s+(%d+)[^\r\n]*[\r\n]*") do --match node entries\r
- pos.x, pos.y, pos.z = originx + tonumber(x), originy + tonumber(y), originz + tonumber(z)\r
- node.name, node.param1, node.param2 = name, param1, param2\r
- add_node(pos, node)\r
- count = count + 1\r
- end\r
- elseif version == 4 then --current nested table format\r
- --wip: this is a filthy hack that works surprisingly well\r
- value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)\r
- local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)\r
- local startpos, startpos1, endpos = 1, 1\r
- local nodes = {}\r
- while true do\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
- startpos, startpos1 = endpos, endpos\r
- end\r
- table.insert(nodes, minetest.deserialize("return " .. value:sub(startpos1)))\r
-\r
- --local nodes = minetest.deserialize(value) --wip: this is broken for larger tables in the current version of LuaJIT\r
-\r
- --load the nodes\r
- count = #nodes\r
- for index = 1, count do\r
- local entry = nodes[index]\r
- entry.x, entry.y, entry.z = originx + entry.x, originy + entry.y, originz + entry.z\r
- add_node(entry, entry) --entry acts both as position and as node\r
- end\r
-\r
- --load the metadata\r
- for index = 1, count do\r
- local entry = nodes[index]\r
+ local origin_x, origin_y, origin_z = origin_pos.x, origin_pos.y, origin_pos.z\r
+ local count = 0\r
+ local add_node, get_meta = minetest.add_node, minetest.get_meta\r
+ for i, entry in ipairs(nodes) do\r
+ entry.x, entry.y, entry.z = origin_x + entry.x, origin_y + entry.y, origin_z + entry.z\r
+ -- Entry acts as both position and node\r
+ add_node(entry, entry)\r
+ if entry.meta then\r