summaryrefslogtreecommitdiff
path: root/Resources/DefaultContent/Libraries/containers/tuple.lua
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-20 13:50:50 +0800
committerchai <chaifix@163.com>2021-10-20 13:50:50 +0800
commitafdcbfa9c4259fb003fd072ae011836230e7e39b (patch)
tree28687805fa6cd08ea998adffeac7b241af42cfe8 /Resources/DefaultContent/Libraries/containers/tuple.lua
parentc795fb754bfd5c84c1bfd7dc793c6519f01109ea (diff)
+containers
Diffstat (limited to 'Resources/DefaultContent/Libraries/containers/tuple.lua')
-rw-r--r--Resources/DefaultContent/Libraries/containers/tuple.lua60
1 files changed, 60 insertions, 0 deletions
diff --git a/Resources/DefaultContent/Libraries/containers/tuple.lua b/Resources/DefaultContent/Libraries/containers/tuple.lua
new file mode 100644
index 0000000..0646d5a
--- /dev/null
+++ b/Resources/DefaultContent/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