-
Notifications
You must be signed in to change notification settings - Fork 143
Extensions
Discordia comes with some general purpose functions. These are added to the Lua standard library when the discordia
module is required.
Serves the same purpose that it does in other languages that feature the same function. In lua, it is a shortcut for print(string.format(...))
Returns the number of elements in a table, one layer deep. This is an alternative to the #
, which should be used for sequentially-indexed tables.
Returns the number of elements in a table, recursively. If a table is encountered, it is recursively counted instead of being added to the total count.
Iterates through a table until it finds a value that is equal to value
according to the ==
operator. The key is returned if a match is found.
Reverses the elements of a sequentially-indexed table, in place.
Returns a copy of a sequentially-indexed table with its elements in reverse order. The original table remains unchanged.
Returns a copy of a table, one layer deep.
Returns a copy of a table, recursively. If a table is encountered, it is recursively deep copied. Metatables are not copied.
Returns a new, sequentially-indexed table, where all of its values are the keys of the original table.
Returns a new, sequentially-indexed table, where all of its values are the values of the original table.
Given a sequentially-indexed table of associatively-indexed sub-tables (objects), this will convert the original table into one where the objects become indexed by a specified key (property).
Given a sequentially-indexed table, this will return a random index, value pair from the table.
Given an associatively-indexed table, this will return a random key, value pair from the table.
Returns a copy of a sequentially-indexed table, sorted using Lua's table.sort
.
Given a two-dimensional, sequentially index table, this will return a new table with the rows and columns swapped.
Splits a string into sub-strings delimited by the specified delim. The sub-strings are returned in a sequentially-indexed table.
Returns a sequentially-indexed table where each element is a character from the original string.
Returns a string where the whitespace is removed from the far left and far right side of the original string.
Adds spaces to the left side of the original string so that the new string is at least as long as the provided length.
Adds spaces to the right side of the original string so that the new string is at least as long as the provided length.
Adds spaces to the left and right side of the original string equally so that the new string is at least as long as the provided length. Priority is given to the right side for odd lengths.
Returns a number that is at least as small as the minimum value and at most as large as the maximum value, inclusively. If it is already within the bounds, the number is returned unchanged.
Returns a number that is rounded to the nearest defined digit. The nearest integer is returned if the digit definition is omitted.