diff --git a/.luacheckrc b/.luacheckrc index 513c02070..dc16259a6 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -27,7 +27,7 @@ read_globals = { "copy", "indexof", "insert_all", "key_value_swap", -- our Core/helpers: -- table: - "contains", "has_value", "has_key", "merge", "merge_values", "is_empty", "overwrite", "keys_of", + "contains", "has_value", "has_key", "merge", "merge_values", "is_empty", "overwrite", "keys_of", "count", "keys", "except", "keys_has_one_of_values", "equals", "multiply_each_value", "apply_function_to_every_value" } }, diff --git a/mods/lord/Core/helpers/src/lua_ext/table.lua b/mods/lord/Core/helpers/src/lua_ext/table.lua index 0be0dc8ff..06332b2ca 100644 --- a/mods/lord/Core/helpers/src/lua_ext/table.lua +++ b/mods/lord/Core/helpers/src/lua_ext/table.lua @@ -244,3 +244,13 @@ function table.apply_function_to_every_value(t, func) end return result end + +--- Use `#table` for numeric +function table.count(table) + local count = 0 + for _, _ in pairs(table) do + count = count + 1 + end + + return count +end