By default Lua doesn't support many table operations even important ones such as indexOf and slice, etc. So this library is to fill that gap.
Currently the functions supported are:-For full documentation refer to the github link,
https://github.com/YoungNeer/lovelib/tree/master/itable
Code: Select all
table.slice(tbl, fromIndex, toIndex, skip)
--make a table from 'fromIndex' to 'toIndex' and skip 'skip-1' elements continually
table.subset(tbl, fromIndex, toIndex)
--same as table.slice just doesn't allow skipping any element between edges
table.firstIndexOf(tbl,element)
--returns the index of the first occurence of the element in given table
table.lastIndexOf(tbl,element)
--returns the index of the first occurence of the element in given table
table.indexOf(tbl,element)
--same as table.firstIndexOf
table.removeAll(tbl,element)
--removes all occurences of an element from table
table.removeDuplicates(tbl,element)
--removes duplicate occurences of an element from table
table.removeAllDuplicates(tbl)
--removes all the duplicate elements from a table
table.reverse(tbl)
--reverses table (in-place)
table.random(tbl)
--gets a random element from given table
table.mix(tbl)
--shuffles table (in-place)
table.shuffle(tbl)
--shuffles table (returns the shuffled table without affecting original table)
table.copy(tbl)
--returns a COPY of table tbl
table.range(from,to,skip)
--returns a table of elements 'from' to 'to' and skips 'skip-1' elements alternatively (3 overloads)
table.append(tbl,value1,value2,...,valuen)
--Push value1,...,valuen to the end of the table
table.merge(main_tbl,tbl1,tbl2,...,tbln)
--Push elements of tbl1 to the end of main_tbl, and so on (for linear array)
table.join(main_tbl,tbl1,tbl2,...,tbln)
--Push elements of tbl1 to the end of main_tbl, and so on (for hash-table)
table.divide(tbl,n)
--divides a linear table into n or n+1 tables
table.subdivide(tbl,n)
--divides a hash-table into n or n+1 tables
table.isort(tbl,funcn)
--sorts table tbl a/c to rule function 'funcn' and returns the sorted table (not in-place)