Module jls.util.tables

Provide table helper functions.

Functions

merge (target, source, keep) Copies the value from the source table into the target.
compare (oldTable, newTable) Returns a table containing the differences between the two specified tables.
patch (oldTable, diff) Returns a table patched according to the specified differences.
getPath (t, path, defaultValue[, separator]) Returns the value at the specified path in the specified table.
setPath (t, path, value[, separator]) Sets the specified value at the specified path in the specified table.
removePath (t, path[, separator]) Removes the value at the specified path in the specified table.
getSchemaValue (schema, value[, translateValues[, onError]]) Returns the value validated by the JSON schema or nil.
createArgumentTable (arguments[, options]) Returns a table containing an entry for each argument name.


Functions

merge (target, source, keep)
Copies the value from the source table into the target. This is a deep copy, sub table are also merged.

Parameters:

  • target table the table to copy.
  • source table a modified table.
  • keep boolean true to indicate that existing target value should be kept, default is false.

Returns:

    table the target table.
compare (oldTable, newTable)
Returns a table containing the differences between the two specified tables. The additions or modifications are availables, the same values are discarded and the deleted values are listed in a specific table entry named "_deleted".

Parameters:

  • oldTable table a base table.
  • newTable table a modified table.

Returns:

    table the differences or nil if there is no such difference.
patch (oldTable, diff)
Returns a table patched according to the specified differences.

Parameters:

  • oldTable table a base table.
  • diff table the differences to apply to the base table.

Returns:

    table the differences or nil if there is no such difference.
getPath (t, path, defaultValue[, separator])
Returns the value at the specified path in the specified table. A path consists in table keys separated by slashes. The key are considered as string, number or boolean. Table or userdata keys are not supported.

Parameters:

  • t table a table.
  • path string the path to look in the table.
  • defaultValue the default value to return if there is no value for the path.
  • separator string the path separator, default is /. (optional)

Returns:

    the value
setPath (t, path, value[, separator])
Sets the specified value at the specified path in the specified table.

Parameters:

  • t table a table.
  • path string the path to set in the table.
  • value the value to set.
  • separator string the path separator. (optional)

Returns:

    the previous value.
removePath (t, path[, separator])
Removes the value at the specified path in the specified table.

Parameters:

  • t table a table.
  • path string the path to remove in the table.
  • separator string the path separator. (optional)

Returns:

    the removed value.
getSchemaValue (schema, value[, translateValues[, onError]])
Returns the value validated by the JSON schema or nil. See https://json-schema.org/

Parameters:

  • schema table the JSON schema.
  • value the value to get from.
  • translateValues boolean true to parse string values and populate objects, default is false. (optional)
  • onError function a function that will be called when a validation error has been found. the function is called with the arguments: code, schema, value, path. (optional)

Returns:

    the value validated against the schema.
createArgumentTable (arguments[, options])
Returns a table containing an entry for each argument name. An entry contains a string or a list of string. An argument name starts with a comma ('-').

Parameters:

  • arguments string the command line containing the arguments.
  • options the options.
    • separator string the path separator, default is the dot ('.'). (optional)
    • emptyPath string the path used for arguments without name, default is zero ('0'). (optional)
    • defaultValues table the default values, could be a module name. (optional)
    • helpPath string the path used to print the help from the schema. (optional)
    • help string the help text to display. (optional)
    • configPath string the path for a configuration file. (optional)
    • configLoader function the function to load the configuration file, could be a module name. (optional)
    • schema table the schema to validate the argument table, could be a module name. (optional)
    • keepComma boolean true to keep leading commas from argument names. (optional)
    • argumentPattern string the pattern used to match the argument name, default is '^-+(.+)$'. (optional)

Returns:

  1. table the arguments as a table.
  2. table the custom arguments from command line and configuration file.
generated by LDoc 1.4.6 Last updated 2022-04-10 21:20:13