summaryrefslogtreecommitdiff
path: root/lualibs-table.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2014-05-05 07:47:48 +0200
committerPhilipp Gesang <phg42.2a@gmail.com>2014-05-05 07:47:48 +0200
commitcc7cbd37b22131aa81a58be88da43ad15ea18436 (patch)
tree056896d2b982ad976e9db1af641913b10c27afce /lualibs-table.lua
parentd758aba692b362c8653e1e4b1b5c13df4346652b (diff)
parentc1310e04a23cfe5d3d795b7e09d91599a3c916a5 (diff)
downloadlualibs-cc7cbd37b22131aa81a58be88da43ad15ea18436.tar.gz
Merge pull request #24 from phi-gamma/master
update to 2.1b
Diffstat (limited to 'lualibs-table.lua')
-rw-r--r--lualibs-table.lua38
1 files changed, 36 insertions, 2 deletions
diff --git a/lualibs-table.lua b/lualibs-table.lua
index c318c57..d231830 100644
--- a/lualibs-table.lua
+++ b/lualibs-table.lua
@@ -88,6 +88,38 @@ local function sortedkeys(tab)
end
end
+local function sortedhashonly(tab)
+ if tab then
+ local srt, s = { }, 0
+ for key,_ in next, tab do
+ if type(key) == "string" then
+ s = s + 1
+ srt[s] = key
+ end
+ end
+ sort(srt)
+ return srt
+ else
+ return { }
+ end
+end
+
+local function sortedindexonly(tab)
+ if tab then
+ local srt, s = { }, 0
+ for key,_ in next, tab do
+ if type(key) == "number" then
+ s = s + 1
+ srt[s] = key
+ end
+ end
+ sort(srt)
+ return srt
+ else
+ return { }
+ end
+end
+
local function sortedhashkeys(tab,cmp) -- fast one
if tab then
local srt, s = { }, 0
@@ -114,8 +146,10 @@ function table.allkeys(t)
return sortedkeys(keys)
end
-table.sortedkeys = sortedkeys
-table.sortedhashkeys = sortedhashkeys
+table.sortedkeys = sortedkeys
+table.sortedhashonly = sortedhashonly
+table.sortedindexonly = sortedindexonly
+table.sortedhashkeys = sortedhashkeys
local function nothing() end