Skip to content

Utility

Utility functions for working in Lua.

Len

Returns the length of a table. The # notation can also be used.

len(ls)
  • table:String input table
  • Number number of items in the table

Get

Get an item from a table using a dot notation path.

get(table, path)
  • table:Table input table
  • path:String dot notation path
  • Any item at the path or nil

First

Get the first item from a table.

first(table)
  • table:Table input table
  • Any first item from the table or nil

Param

Get a parameter from the enviroment.

param(path)
  • path:String path to the parameter
  • Any Item available at that path or nil

Mock

Add a parameter to the enviroment for testing purposes; if there are actual environment values they will override the parameters supplied to mock.

mock(path, value)
  • path:String path to the enviroment
  • value:Any any value

No return value

FromJson

Convert a JSON string to a Lua table.

FromJson(text)
  • text:String string as serialized JSON
  • Table Lua table

ToJson

Convert a Lua table to a serialized JSON string

FromJson(table)
  • table:Table Lua table
  • String serialized JSON string

Sleep

Sleeps for a period of time. The Sleep function can be used to throttle script behavior or allow reads to catch up with writes.

  • There can be 50-100 ms delay between writing values and them being available for read.
  • If the script consumes all available allocated CPU for an extended period it will be terminated.

If the script processes a very large list of data and contains many read or write requests use Sleep to keep the script from consuming all available resources.

Sleep(ms)
  • ms:Number milliseconds to sleep for

No return value

ToLocalDate

Convert a string to a date.

ToLocalDate(value)
  • value:String parseable string representing a date in ISO8601 format

Date

FormatDate

Parse a string in ISO8601 format to a date and then format for usage. Use the following date formats. Some example ISO8601 strings include 2008-03-01, 20080301 and 2008-03-01T13:00:00Z.

FormatDate(value, format)
  • value:String parseable string representing a date in ISO8601 format
  • format:String date format

String