Module pico8lib.tables
Table manipulation and creation
get (t, k[, d]) |
Get value from table by key, with default |
add_ (a, v) |
Add value to end of array
supposedly faster but less safe than add(a,v) |
del_r (a, v) |
Delete value from array, do not preserve order |
deli_r (a, i) |
Delete index from array, do not preserve order |
shift (a) |
Delete and return the first item from array |
unshift (a, v) |
Add value to the beginning of array |
rand_array (a) |
Select a random value from an array |
merge (d, s) |
Copy keys, values, and metatable from one table to another, using copy() |
copy (o) |
Create a copy of a variable, a deep copy if it's a table, using merge() |
copy_merge (o[, t]) |
Create a copy of a variable, a deep copy if it's a table, optionally merging another table over the copy |
table_copy (o) |
Create a deep copy of a table |
table_compare (a, b) |
Recursive/deep comparison of two tables |
table_compare_meta (a, b) |
Recursive/deep comparison of two tables and their metatables |
concat (d, s) |
Add values from one array to the end of another |
shuffle (a) |
Randomize the order of a table using fisher-yates shuffle |
sort_slow (a) |
Sort an array in place, the slowest way |
sort_slow_reverse (a) |
Sort an array in place, in descending order, the slowest way |
sort_slow_func (a, f) |
Sort an array in place, the slowest way, with a key function |
sort_slow_func_unsafe (a, f) |
Sort an array in place, the slowest way, with a key function |
sort_slow_cmp (a, f) |
Sort an array in place, the slowest way, with a comparison function |
sort_quick (a[, i[, j]]) |
Sort an array in place, modified quicksort
quicksort chooses a pivot value, rearranges the table into {vals<=pivot, pivot, vals>=pivot}, recurses on both sides |
sort_quick_func (a, f[, i[, j]]) |
Sort an array in place, modified quicksort, with a key function |
sort_quick_cmp (a, f[, i[, j]]) |
Sort an array in place, modified quicksort, with a comparison function |
sort |
Default sort function |
filter (t, check) |
Filter a table, keeping only key,value pairs that pass a check function
return a new table with the same keys/indices kept from the original |
filter_array (t, check) |
Filter an array, keeping only values that pass check function
return a new array with sequential indices |
-
all_reverse (t)
-
Iterate an array in reverse
used just like all()
Parameters:
-
reverse (a)
-
Reverse the items in an array, in place
Parameters:
-
get (t, k[, d])
-
Get value from table by key, with default
Parameters:
- t
table
The table to reference
- k
The key to access
- d
A default value to return if the key is not present in the table
(optional)
Returns:
Either the associated value or the default
-
add_ (a, v)
-
Add value to end of array
supposedly faster but less safe than add(a,v)
Parameters:
-
del_r (a, v)
-
Delete value from array, do not preserve order
Parameters:
- a
array
- v
value to delete
-
deli_r (a, i)
-
Delete index from array, do not preserve order
Parameters:
-
shift (a)
-
Delete and return the first item from array
Parameters:
Returns:
value of a[1] prior to deletion
-
unshift (a, v)
-
Add value to the beginning of array
Parameters:
-
rand_array (a)
-
Select a random value from an array
Parameters:
- a
array
array to choose from
Returns:
randomly chosen item from array
-
merge (d, s)
-
Copy keys, values, and metatable from one table to another, using copy()
Parameters:
Returns:
table
d
-
copy (o)
-
Create a copy of a variable, a deep copy if it's a table, using merge()
Parameters:
Returns:
copy of o
-
copy_merge (o[, t])
-
Create a copy of a variable, a deep copy if it's a table, optionally merging another table over the copy
Parameters:
- o
variable to copy
- t
table
table to merge over the copy
(optional)
Returns:
copy of o, optionally merged with t
-
table_copy (o)
-
Create a deep copy of a table
Parameters:
Returns:
table
copy of o
-
table_compare (a, b)
-
Recursive/deep comparison of two tables
Parameters:
Returns:
boolean
true iff tables have equal contents
-
table_compare_meta (a, b)
-
Recursive/deep comparison of two tables and their metatables
Parameters:
Returns:
boolean
true iff tables have equal contents and metatable contents
-
concat (d, s)
-
Add values from one array to the end of another
Parameters:
- d
array
destination
- s
array
source
-
shuffle (a)
-
Randomize the order of a table using fisher-yates shuffle
Parameters:
- a
array
array to shuffle in place
-
sort_slow (a)
-
Sort an array in place, the slowest way
Parameters:
- a
array
array to sort in place
-
sort_slow_reverse (a)
-
Sort an array in place, in descending order, the slowest way
Parameters:
- a
array
array to sort in place
-
sort_slow_func (a, f)
-
Sort an array in place, the slowest way, with a key function
Parameters:
- a
array
array to sort in place
- f
function
function to extract or calculate a comparison key for each value, run once per value
-
sort_slow_func_unsafe (a, f)
-
Sort an array in place, the slowest way, with a key function
Parameters:
- a
array
array to sort in place
- f
function
function to extract or calculate a comparison key for each valuem run multiple times per value
-
sort_slow_cmp (a, f)
-
Sort an array in place, the slowest way, with a comparison function
Parameters:
- a
array
array to sort in place
- f
function
function to compare two values
-
sort_quick (a[, i[, j]])
-
Sort an array in place, modified quicksort
quicksort chooses a pivot value, rearranges the table into {vals<=pivot, pivot, vals>=pivot}, recurses on both sides
Parameters:
- a
array
the table to sort
- i
number
starting index of slice to sort
(optional)
- j
number
ending index of slice to sort
(optional)
-
sort_quick_func (a, f[, i[, j]])
-
Sort an array in place, modified quicksort, with a key function
Parameters:
- a
array
the table to sort
- f
function
function to extract or calculate a comparison key for each value
- i
number
starting index of slice to sort
(optional)
- j
number
ending index of slice to sort
(optional)
-
sort_quick_cmp (a, f[, i[, j]])
-
Sort an array in place, modified quicksort, with a comparison function
Parameters:
- a
array
the table to sort
- f
function
function to compare two values
- i
number
starting index of slice to sort
(optional)
- j
number
ending index of slice to sort
(optional)
-
sort
-
Default sort function
-
filter (t, check)
-
Filter a table, keeping only key,value pairs that pass a check function
return a new table with the same keys/indices kept from the original
Parameters:
-
filter_array (t, check)
-
Filter an array, keeping only values that pass check function
return a new array with sequential indices
Parameters:
-
pred_any (t)
-
Determine if any value in a table is truthy
Parameters:
-
pred_any_func (t, check)
-
Determine if any value in a table passes check function
Parameters:
-
pred_all (t)
-
Determine if every value in a table is truthy
Parameters:
-
pred_all_func (t, check)
-
Determine if every value in a table is truthy or passes check function
Parameters: