Skip to content

Commit

Permalink
Merge pull request #15 from nixnoxus/walk_over_all_with_optional_key
Browse files Browse the repository at this point in the history
add optional parameter `key` to `tubelib2.walk_over_all`
  • Loading branch information
joe7575 authored Apr 28, 2022
2 parents 109f117 + b4c7a0e commit a459834
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,22 @@ function tubelib2.get_mem_data(pos, key, default)
return tubelib2.get_mem(pos)[key] or default
end

function tubelib2.walk_over_all(clbk)
function tubelib2.walk_over_all(clbk, key)
local data = storage:to_table()
for block_key,sblock in pairs(data.fields) do
local block = minetest.deserialize(sblock)
for node_key,mem in pairs(block) do
if mem then
if node_key ~= "used" and node_key ~= "best_before" then
if mem and 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 node = tubelib2.get_node_lvm(pos)
clbk(pos, node, mem)
if key ~= nil then
-- only specified 'key'
clbk(pos, node, {[key] = mem[key]})
else
-- without specified 'key'
clbk(pos, node, mem)
end
end
end
end
Expand Down

0 comments on commit a459834

Please sign in to comment.