From 19ba6b14e20738c82ad539b2a4b0690e7880e3cb Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 1 Feb 2017 08:18:28 +0100 Subject: sync with Context as of 2017-02-01 --- lualibs-util-tab.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lualibs-util-tab.lua') 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) -- cgit v1.2.3