mirror of
https://github.com/joe7575/tubelib2.git
synced 2024-12-01 03:43:45 +01:00
add optional parameter key
to tubelib2.walk_over_all
This commit is contained in:
parent
109f117f78
commit
b4c7a0ed26
12
storage.lua
12
storage.lua
@ -129,18 +129,24 @@ function tubelib2.get_mem_data(pos, key, default)
|
|||||||
return tubelib2.get_mem(pos)[key] or default
|
return tubelib2.get_mem(pos)[key] or default
|
||||||
end
|
end
|
||||||
|
|
||||||
function tubelib2.walk_over_all(clbk)
|
function tubelib2.walk_over_all(clbk, key)
|
||||||
local data = storage:to_table()
|
local data = storage:to_table()
|
||||||
for block_key,sblock in pairs(data.fields) do
|
for block_key,sblock in pairs(data.fields) do
|
||||||
local block = minetest.deserialize(sblock)
|
local block = minetest.deserialize(sblock)
|
||||||
for node_key,mem in pairs(block) do
|
for node_key,mem in pairs(block) do
|
||||||
if mem then
|
if mem and node_key ~= "used" and node_key ~= "best_before" then
|
||||||
if node_key ~= "used" and node_key ~= "best_before" then
|
if key == nil or (type(mem) == "table" and mem[key] ~= nil) then
|
||||||
local pos = keys_to_pos(block_key, node_key)
|
local pos = keys_to_pos(block_key, node_key)
|
||||||
local node = tubelib2.get_node_lvm(pos)
|
local node = tubelib2.get_node_lvm(pos)
|
||||||
|
if key ~= nil then
|
||||||
|
-- only specified 'key'
|
||||||
|
clbk(pos, node, {[key] = mem[key]})
|
||||||
|
else
|
||||||
|
-- without specified 'key'
|
||||||
clbk(pos, node, mem)
|
clbk(pos, node, mem)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user