From: Jo-Philipp Wich Date: Sun, 17 Aug 2008 14:56:03 +0000 (+0000) Subject: * luci/libs: add keys() to luci.util X-Git-Tag: 0.8.0~386 X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=commitdiff_plain;h=c7ba7f99b04178e839f343b4f3e17cf3c18ea75a * luci/libs: add keys() to luci.util --- diff --git a/libs/core/luasrc/util.lua b/libs/core/luasrc/util.lua index ef1b8fe27..c6d9ec6ce 100644 --- a/libs/core/luasrc/util.lua +++ b/libs/core/luasrc/util.lua @@ -358,6 +358,19 @@ function update(t, updates) end end +--- Retrieve all keys of given associative table. +-- @param t Table to extract keys from +-- @return Sorted table containing the keys +function keys(t) + local keys = { } + if t then + for k, _ in kspairs(t) do + table.insert( keys, k ) + end + end + return keys +end + --- Clones the given object and return it's copy. -- @param object Table value to clone -- @param deep Boolean indicating whether to do recursive cloning