Module luarocks.util

(no description)

Functions

schedule_function (f, ...) Schedule a function to be executed upon program termination.
remove_scheduled_function (table:, item) Unschedule a function.
run_scheduled_functions () Execute scheduled functions.
parse_flags (...) Extract flags from an arguments list.
deep_merge (dst, src) Merges contents of src on top of dst's contents.
platform_overrides (tbl) Perform platform-specific overrides on a table.
warning (msg) Display a warning message.
variable_substitutions (tbl, vars) Perform make-style variable substitutions on string values of a table.
keys (tbl) Return an array of keys of a table.
sortedpairs (tbl, sort_function) A table iterator generator that returns elements sorted by key, to be used in "for" loops.


Functions

schedule_function (f, ...)
Schedule a function to be executed upon program termination. This is useful for actions such as deleting temporary directories or failure rollbacks.

Parameters:

  • f: function: Function to be executed.
  • ...: arguments to be passed to function.

Returns:

    table: A token representing the scheduled execution, which can be used to remove the item later from the list.
remove_scheduled_function (table:, item)
Unschedule a function. This is useful for cancelling a rollback of a completed operation.

Parameters:

  • table:: The token representing the scheduled function that was returned from the schedule_function call.
  • item:
run_scheduled_functions ()
Execute scheduled functions. Some calls create temporary files and/or directories and register corresponding cleanup functions. Calling this function will run these function, erasing temporaries. Functions are executed in the inverse order they were scheduled.
parse_flags (...)
Extract flags from an arguments list. Given string arguments, extract flag arguments into a flags set. For example, given "foo", "--tux=beep", "--bla", "bar", "--baz", it would return the following: {["bla"] = true, ["tux"] = "beep", ["baz"] = true}, "foo", "bar".

Parameters:

  • ...:
deep_merge (dst, src)
Merges contents of src on top of dst's contents.

Parameters:

  • dst: Destination table, which will receive src's contents.
  • src: Table which provides new contents to dst.

see also:

platform_overrides (tbl)
Perform platform-specific overrides on a table. Overrides values of table with the contents of the appropriate subset of its "platforms" field. The "platforms" field should be a table containing subtables keyed with strings representing platform names. Names that match the contents of the global cfg.platforms setting are used. For example, if cfg.platforms= {"foo"}, then the fields of tbl.platforms.foo will overwrite those of tbl with the same names. For table values, the operation is performed recursively (tbl.platforms.foo.x.y.z overrides tbl.x.y.z; other contents of tbl.x are preserved).

Parameters:

  • tbl: table or nil: Table which may contain a "platforms" field; if it doesn't (or if nil is passed), this function does nothing.
warning (msg)
Display a warning message.

Parameters:

  • msg: string: the warning message
variable_substitutions (tbl, vars)
Perform make-style variable substitutions on string values of a table. For every string value tbl.x which contains a substring of the format "$(XYZ)" will have this substring replaced by vars["XYZ"], if that field exists in vars. Only string values are processed; this function does not scan subtables recursively.

Parameters:

  • tbl: table: Table to have its string values modified.
  • vars: table: Table containing string-string key-value pairs representing variables to replace in the strings values of tbl.
keys (tbl)
Return an array of keys of a table.

Parameters:

  • tbl: table: The input table.

Returns:

    table: The array of keys.
sortedpairs (tbl, sort_function)
A table iterator generator that returns elements sorted by key, to be used in "for" loops.

Parameters:

  • tbl: table: The table to be iterated.
  • sort_function: function or nil: An optional comparison function to be used by table.sort when sorting keys.

Returns:

    function: the iterator function.
generated by LDoc 0.5