@@ -14,6 +14,10 @@ local str = tostring
14
14
local int = tonumber
15
15
16
16
local function len (t )
17
+ if type (t ._data ) == " table" then
18
+ return # t ._data
19
+ end
20
+
17
21
return # t
18
22
end
19
23
@@ -43,18 +47,20 @@ local function range(from, to, step)
43
47
end
44
48
45
49
local function list (t )
50
+ local result = {}
51
+
46
52
local methods = {}
47
53
48
54
methods .append = function (value )
49
- table.insert (t , value )
55
+ table.insert (result . _data , value )
50
56
end
51
57
52
58
local iterator_index = nil
53
59
54
- setmetatable (t , {
60
+ setmetatable (result , {
55
61
__index = function (self , index )
56
62
if type (index ) == " number" and index < 0 then
57
- return rawget (t , # t + index + 1 )
63
+ return rawget (result . _data , # result . _data + index + 1 )
58
64
end
59
65
60
66
return methods [index ]
@@ -65,22 +71,29 @@ local function list(t)
65
71
end
66
72
67
73
local v = nil
68
- iterator_index , v = next (t , iterator_index )
74
+ iterator_index , v = next (result . _data , iterator_index )
69
75
70
76
return v
71
77
end ,
72
78
})
73
79
74
- t .is_list = true
80
+ result .is_list = true
81
+
82
+ result ._data = {}
83
+ for _ , v in ipairs (t ) do
84
+ table.insert (result ._data , v )
85
+ end
75
86
76
- return t
87
+ return result
77
88
end
78
89
79
90
function dict (t )
91
+ local result = {}
92
+
80
93
local methods = {}
81
94
82
95
methods .items = function ()
83
- return pairs (t )
96
+ return pairs (result . _data )
84
97
end
85
98
86
99
local key_index = nil
@@ -92,15 +105,20 @@ function dict(t)
92
105
key_index = nil
93
106
end
94
107
95
- key_index , _ = next (t , key_index )
108
+ key_index , _ = next (result . _data , key_index )
96
109
97
110
return key_index
98
111
end ,
99
112
})
100
113
101
- t .is_dict = true
114
+ result .is_dict = true
115
+
116
+ result ._data = {}
117
+ for k , v in pairs (t ) do
118
+ result ._data [k ] = v
119
+ end
102
120
103
- return t
121
+ return result
104
122
end
105
123
106
124
function enumerate (t , start )
0 commit comments