在Lua中将多键元组映射为多值元组

Lua中是否有支持从元组到元组的映射的库?我有一个键 {a,b,c} 要映射到值 {c,d,e}。有一些库,比如 http://lua-users.org/wiki/MultipleKeyIndexing,支持多键,但值不是元组。

点赞
用户2242940
用户2242940

以下是使用 Egor 的字符串连接建立键的一种方式,创建自己的简单的插入和获取方法用于表 t。

local a, b, c = 10, 20, 30
local d, e, f = 100, 200, 300

local t = {}
t.key = function (k)
  local key = ""
  for _,v in ipairs(k) do
     key = key .. tostring(v) .. ";"
   end
   return key
end
t.set = function (k, v)
  local key = t.key(k)
  t[key] = v
end
t.get = function (k)
  local key = t.key(k)
  return t[key]
end

t.set ({a, b, c}, {d, e, f})           -- 使用变量
t.set ({40, 50, 60}, {400, 500, 600})  -- 使用常量

local w = t.get ({a, b, c})               -- 使用变量
local x = t.get ({40, 50, 60})            -- 使用常量

print(w[1], w[2], w[3])                   -- 100    200    300
print(x[1], x[2], x[3])                   -- 400    500    600
2019-03-08 03:37:14