-
Notifications
You must be signed in to change notification settings - Fork 8
Table Manipulation
This library provides generic functions for table manipulation. It provides all its functions inside the table "table".
Table indices in Killa are 0 based (like in C).
Given a list where all elements are strings or numbers, returns list[i]..sep..list[i+1] ··· sep..list[j]. The default value for sep is the empty string, the default for i is 0, and the default for j is ($list - 1). If i is greater than j, returns the empty string.
Inserts element value at position pos in list, shifting up the elements list[pos], list[pos+1], ···, list[$list - 1]. The default value for pos is $list, so that a call table.insert(t,x) inserts x at the end of list t.
Removes from list the element at position pos, shifting down the elements list[pos+1], list[pos+2], ···, list[$list - 1] and erasing element list[$list - 1]. Returns the value of the removed element. The default value for pos is ($list - 1), so that a call table.remove(t) removes the last element of list t.
Sorts list elements in a given order, in-place, from list[0] to list[$list - 1]. If comp is given, then it must be a function that receives two list elements and returns true when the first element must come before the second in the final order (so that comp(list[i+1],list[i]) will be false after the sort). If comp is not given, then the standard operator < is used instead.
The sort algorithm is not stable; that is, elements considered equal by the given order may have their relative positions changed by the sort.