-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtuple.lua
60 lines (44 loc) · 1.1 KB
/
tuple.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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