diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2014-03-16 16:11:34 +0100 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2014-03-16 16:11:34 +0100 |
commit | f8fa3ab7afa4746d534a8d660b7d6bf9d28a0e9c (patch) | |
tree | 4fb31c6dd459a3717c60e445bedb1e82d4560c70 /lualibs-table.lua | |
parent | 5ed9c2a6d45121bdeacdf1c8f4dead50374f0899 (diff) | |
download | lualibs-f8fa3ab7afa4746d534a8d660b7d6bf9d28a0e9c.tar.gz |
sync with Context as of 2014-03-16
Diffstat (limited to 'lualibs-table.lua')
-rw-r--r-- | lualibs-table.lua | 38 |
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 |