@@ -143,7 +143,7 @@ function ql.new(_table)
143143 end
144144
145145 -- Check if a value exists in the table.
146- -- Returns index of value if it exists.
146+ -- Returns first index of value if it exists.
147147 -- Returns nil if it doesn't.
148148 function self .find (value )
149149 local index = nil
@@ -207,7 +207,7 @@ function ql.new(_table)
207207
208208 -- Return a new QuickList by flattening nested tables.
209209 function self .flatten ()
210- local flat = ql .new (flattenTable (self ))
210+ local flat = ql .new (flattenTable (self . t ))
211211 return flat
212212 end
213213
@@ -243,6 +243,7 @@ function ql.new(_table)
243243 return true
244244 end
245245
246+ -- Check if a table is a QuickList
246247 function self .checkql (tab )
247248 if not type (tab ) == ' table' then return false end
248249 local mt = getmetatable (tab )
256257function flattenTable (tab )
257258 local flat = {}
258259 for i = 1 , # tab do
260+ print (tab [i ])
259261 if type (tab [i ]) == ' table' then
260262 for e ,j in ipairs (flattenTable (tab [i ])) do
261263 table.insert (flat ,j )
270272function setupql ()
271273 function ql .__index (self , key )
272274 if tonumber (key ) then
273- return self .t [key ]
275+ return self .t [getNegativeIndex ( self , key ) ]
274276 end
275277 end
276278
@@ -280,7 +282,7 @@ function setupql()
280282 local _end = # self .t
281283 local _inter = 1
282284 if # index > 1 then
283- _end = index [2 ]
285+ _end = getNegativeIndex ( self , index [2 ])
284286 if # index == 3 then
285287 _inter = index [3 ]
286288 end
@@ -331,4 +333,10 @@ function concat(tab, sep)
331333 return str
332334end
333335
336+ function getNegativeIndex (tab , index )
337+ if index < 1 then
338+ return # tab + index
339+ end
340+ end
341+
334342return ql .new
0 commit comments