Module tab

table utility

Functions

print (t) print the contents of a table
sort (t) return a lexigraphically sorted array of keys for a table
count (t) count the number of entries in a table; unlike table.getn() or #table, nil entries won't break the loop
contains (t, e) search table for element
invert (t) given a simple table of primitives, "invert" it so that values become keys and vice versa.
key (t, e) search table for element, return key
lines (str) split multi-line string into table of strings
split (inputstr, sep) split string into table with delimiter
save (tbl, filename) Save a table to disk.
load (sfile) Load a table that has been saved via the tab.save() function.


Functions

print (t)
print the contents of a table

Parameters:

sort (t)
return a lexigraphically sorted array of keys for a table

Parameters:

Returns:

    table sorted table
count (t)
count the number of entries in a table; unlike table.getn() or #table, nil entries won't break the loop

Parameters:

Returns:

    number count
contains (t, e)
search table for element

Parameters:

  • t table table to check
  • e element to look for

Returns:

    boolean t/f is element is present
invert (t)
given a simple table of primitives, "invert" it so that values become keys and vice versa. this allows more efficient checks on multiple values

Parameters:

  • t a simple table
key (t, e)
search table for element, return key

Parameters:

  • t table table to check
  • e element to look for

Returns:

    key, nil if not found
lines (str)
split multi-line string into table of strings

Parameters:

  • str string string with line breaks

Returns:

    table table with entries for each line
split (inputstr, sep)
split string into table with delimiter

Parameters:

save (tbl, filename)
Save a table to disk. Saves tables, numbers, booleans and strings. Inside table references are saved. Does not save userdata, metatables, functions and indices of these. Based on http://lua-users.org/wiki/SaveTableToFile by ChillCode.

Parameters:

  • tbl table Table to save.
  • filename string Location to save to.

Returns:

    On failure, returns an error msg.
load (sfile)
Load a table that has been saved via the tab.save() function.

Parameters:

  • sfile string Filename or stringtable to load.

Returns:

    On success, returns a previously saved table. On failure, returns as second argument an error msg.
generated by LDoc 1.5.0 Last updated 2024-01-13 13:12:10