diff options
author | chai <chaifix@163.com> | 2021-11-15 11:54:17 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-15 11:54:17 +0800 |
commit | 30f2f46474bf4eda5f10d4c64a07cde01d469f66 (patch) | |
tree | 6ff2ed3262037b3c9bae2d2b9059a1d65773f31c /Data/BuiltIn/Libraries/containers/tuple.lua | |
parent | 4c36bed53fe63ae6056730b3ecad2573f03d88f8 (diff) |
*rename DefaultContent -> BuiltIn
Diffstat (limited to 'Data/BuiltIn/Libraries/containers/tuple.lua')
-rw-r--r-- | Data/BuiltIn/Libraries/containers/tuple.lua | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Data/BuiltIn/Libraries/containers/tuple.lua b/Data/BuiltIn/Libraries/containers/tuple.lua new file mode 100644 index 0000000..0646d5a --- /dev/null +++ b/Data/BuiltIn/Libraries/containers/tuple.lua @@ -0,0 +1,60 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by Dee. +--- DateTime: 2019/3/7 14:00 +--- 元組,對修改關閉 +--- + +tuple = tuple or {} + +function tuple.create(i_data) + assert(type(i_data) == "table", ">> Dee: shoudle create with table") + + local data = {} + for k,v in pairs(i_data) do + data[#data+1] = v + end + + local t = {} + + local __tostring = function() + return table.concat(data, ",") + end + + local __index = function(i_t, key) + return data[key] + end + + local __newindex = function(i_t, key, v) + error(">> Dee: Limited access") + end + + local __pairs = function() + error(">> Dee: Limited access") + end + + local __ipairs = function(i_t) + local idx = 0 + local function iter(i_t) + idx = idx + 1 + if idx <= #data then + return idx, data[idx] + end + end + + return iter + end + + local __len = function(v) + return #data + end + + local mt = {__tostring = __tostring, __index = __index, __newindex = __newindex, __pairs =__pairs, __ipairs = __ipairs, __len = __len} + + setmetatable(t, mt) + + return t + end + + +return tuple
\ No newline at end of file |