From afced71a9aec841c4b0b757a3cdd716e77ba09ea Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Mon, 22 Mar 2021 20:55:40 +0100 Subject: [PATCH] Add example for gears.table.count_keys Signed-off-by: Lucas Schwiderski --- lib/gears/table.lua | 2 ++ tests/examples/text/gears/table/count_keys.lua | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 tests/examples/text/gears/table/count_keys.lua diff --git a/lib/gears/table.lua b/lib/gears/table.lua index 7d4f00bd5..e1744f280 100644 --- a/lib/gears/table.lua +++ b/lib/gears/table.lua @@ -169,6 +169,8 @@ end -- -- This is functionally equivalent, but faster than `#gears.table.keys(t)`. -- +-- @DOC_text_gears_table_count_keys_EXAMPLE@ +-- -- @tparam table t The table for which to count the keys. -- @treturn number The number of keys in the table. -- @staticfct gears.table.count_keys diff --git a/tests/examples/text/gears/table/count_keys.lua b/tests/examples/text/gears/table/count_keys.lua new file mode 100644 index 000000000..543db2b12 --- /dev/null +++ b/tests/examples/text/gears/table/count_keys.lua @@ -0,0 +1,6 @@ +--DOC_GEN_OUTPUT --DOC_HIDE +local gears = require("gears") --DOC_HIDE + +local tab = { 1, nil, "a", "b", foo = "bar" } +local count = gears.table.count_keys(tab) +print("The table has " .. count .. " keys")