Add table.count function to mcl_util
This commit is contained in:
parent
9996c75de5
commit
4a15625de7
@ -216,6 +216,7 @@ read_globals = {
|
||||
"key_value_swap",
|
||||
"shuffle",
|
||||
reverse = { read_only = false },
|
||||
count = { read_only = false },
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user