summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua30
1 files changed, 27 insertions, 3 deletions
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua
index 11cb66bef1e..f361f3d20c4 100644
--- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua
+++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-table.lua
@@ -129,10 +129,13 @@ local function sortedhash(t,cmp)
s = sortedkeys(t) -- the robust one
end
local n = 0
+ local m = #s
local function kv(s)
- n = n + 1
- local k = s[n]
- return k, t[k]
+ if n < m then
+ n = n + 1
+ local k = s[n]
+ return k, t[k]
+ end
end
return kv, s
else
@@ -1054,3 +1057,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