Module tabutil

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
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.
readonly (params) Create a read-only proxy for a given table.


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
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.
readonly (params)
Create a read-only proxy for a given table.

Parameters:

  • params params.table is the table to proxy, params.except a list of writable keys

Returns:

    table the proxied read-only table
generated by LDoc 1.4.6 Last updated 2019-12-28 20:46:36