Add table.count function to mcl_util

This commit is contained in:
cora 2024-03-19 22:00:28 +01:00
parent 9996c75de5
commit 4a15625de7
2 changed files with 11 additions and 0 deletions

View File

@ -216,6 +216,7 @@ read_globals = {
"key_value_swap",
"shuffle",
reverse = { read_only = false },
count = { read_only = false },
}
},

View File

@ -36,6 +36,16 @@ function table.reverse(t)
end
end
function table.count(t, does_it_count)
local r = 0
for k, v in pairs(t) do
if does_it_count == nil or ( type(does_it_count) == "function" and does_it_count(k, v) ) then
r = r + 1
end
end
return r
end
local LOGGING_ON = minetest.settings:get_bool("mcl_logging_default", false)
local LOG_MODULE = "[MCL2]"
function mcl_util.mcl_log(message, module, bypass_default_logger)