summaryrefslogtreecommitdiff
path: root/lualibs-util-tab.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2017-02-01 08:18:28 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2017-02-01 08:18:28 +0100
commit19ba6b14e20738c82ad539b2a4b0690e7880e3cb (patch)
treefa23bc0113f3a8f141e2ecd06a1d352665f408d7 /lualibs-util-tab.lua
parent12d27922f7bb7f466b5d476fa2c1ddc08a300513 (diff)
downloadlualibs-19ba6b14e20738c82ad539b2a4b0690e7880e3cb.tar.gz
sync with Context as of 2017-02-01
Diffstat (limited to 'lualibs-util-tab.lua')
-rw-r--r--lualibs-util-tab.lua13
1 files changed, 6 insertions, 7 deletions
diff --git a/lualibs-util-tab.lua b/lualibs-util-tab.lua
index 9266598..0521a2a 100644
--- a/lualibs-util-tab.lua
+++ b/lualibs-util-tab.lua
@@ -486,12 +486,12 @@ end
local selfmapper = { __index = function(t,k) t[k] = k return k end }
-function table.twowaymapper(t)
- if not t then
- t = { }
- else
- local zero = rawget(t,0)
- for i=zero or 1,#t do
+function table.twowaymapper(t) -- takes a 0/1 .. n indexed table and returns
+ if not t then -- it with string-numbers as indices + reverse
+ t = { } -- mapping (all strings) .. used in cvs etc but
+ else -- typically a helper that one forgets about
+ local zero = rawget(t,0) -- so it might move someplace else
+ for i=zero and 0 or 1,#t do
local ti = t[i] -- t[1] = "one"
if ti then
local i = tostring(i)
@@ -499,7 +499,6 @@ function table.twowaymapper(t)
t[ti] = i -- t["one"] = "1"
end
end
- t[""] = zero or ""
end
-- setmetatableindex(t,"key")
setmetatable(t,selfmapper)