Provide a variety of utility Table operations

Members

Functions

Returns Functions Description
table lib.Append ( table target table source ) Concats target with source
table lib.Merge ( table orig table new ) Shallow merges two tables without modifying either
list lib.ToList ( table tab ) Converts a table to a list
number lib.Count ( table tab ) Counts the number of items in tab.
table lib.Copy ( table target ) Copies a table, but not deep.
table lib.DeepCopy ( table table ) Deep copies a table including metatables
table lib.DeepOverwrite ( table target table source ) Overwrites a table's value
nil lib.GetIndex ( table haystack needle ) Gets an index by value, returning nil if no index is found.
string lib.Stringify ( table table number indent = 0 string output = "" ) Recursively prints the table.
boolean lib.Contains ( table table value ) Returns whether value is within table
table lib.Overwrite ( table target table source ) Overwrites an existing table
table lib.ReadOnly ( table table ) Sets a metatable on a table such that it errors when indexing a nil value

Functions Descriptions

table lib.Append ( table target table source )

Concats target with source

Parameters

  • table target: Table to append to
  • table source: Table read from

Returns

table lib.Merge ( table orig table new )

Shallow merges two tables without modifying either

Parameters

Returns

list lib.ToList ( table tab )

Converts a table to a list

Parameters

  • table tab: Table to convert to a list

Returns

number lib.Count ( table tab )

Counts the number of items in tab. Useful since __len on table in Lua 5.2 returns just the array length.

Parameters

  • table tab: Table to count

Returns

table lib.Copy ( table target )

Copies a table, but not deep.

Parameters

  • table target: Table to copy

Returns

table lib.DeepCopy ( table table )

Deep copies a table including metatables

Parameters

  • table table: Table to deep copy

Returns

table lib.DeepOverwrite ( table target table source )

Overwrites a table's value

Parameters

  • table target: Target table
  • table source: Table to read from

Returns

nil lib.GetIndex ( table haystack needle )

Gets an index by value, returning nil if no index is found.

Parameters

  • table haystack: to search in
  • needle: Value to search for

Returns

  • The index of the value, if found
  • nil: if not found

string lib.Stringify ( table table number indent = 0 string output = "" )

Recursively prints the table. Does not handle recursive tables.

Parameters

  • table table: Table to stringify
  • number indent = 0: Indent level
  • string output = "": Output string, used recursively

Returns

  • string: The table in string form

boolean lib.Contains ( table table value )

Returns whether value is within table

Parameters

  • table table: to search in for value
  • value: Value to search for

Returns

  • boolean: true if within, false otherwise

table lib.Overwrite ( table target table source )

Overwrites an existing table

Parameters

  • table target: Table to overwite
  • table source: Source table to read from

Returns

table lib.ReadOnly ( table table )

Sets a metatable on a table such that it errors when indexing a nil value

Parameters

  • table table: Table to error on indexing

Returns

  • table: table The same table