summaryrefslogtreecommitdiff
path: root/lualibs-table.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lualibs-table.lua')
-rw-r--r--lualibs-table.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/lualibs-table.lua b/lualibs-table.lua
index 11cb66b..c6bbc62 100644
--- a/lualibs-table.lua
+++ b/lualibs-table.lua
@@ -1054,3 +1054,24 @@ function table.sorted(t,...)
sort(t,...)
return t -- still sorts in-place
end
+
+--
+
+function table.values(t,s) -- optional sort flag
+ if t then
+ local values, keys, v = { }, { }, 0
+ for key, value in next, t do
+ if not keys[value] then
+ v = v + 1
+ values[v] = value
+ keys[k] = key
+ end
+ end
+ if s then
+ sort(values)
+ end
+ return values
+ else
+ return { }
+ end
+end