Module luarocks.util

Utility functions shared by other modules.

Functions

parse_flags (...) Extract flags from an arguments list.
platform_overrides (tbl) Perform platform-specific overrides on a table.
remove_scheduled_function (item) Unschedule a function.
run_scheduled_functions () Execute scheduled functions.
schedule_function (f, ...) Schedule a function to be executed upon program termination.
variable_substitutions (tbl, vars) Perform make-style variable substitutions on string values of a table.


Functions

parse_flags (...)
Extract flags from an arguments list. Given string arguments (for example, "foo", "--bla", "bar", "--baz"), extract flag arguments into a flags set (returning for the previous example {["--bla"] = true, ["--baz"] = true}, "foo", "bar").

Parameters

  • ...:
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 config.platforms setting are used. For example, if config.platforms= {"plat"}, then the fields of tbl.platforms.plat will overwrite those of tbl with the same names. For table values, the operation is performed recursively (tbl.platforms.plat.x.y.z overrides tbl.x.y.z; other contents of tbl.x are preserved).

Parameters

  • tbl: table: Table which may contain a "platforms" field; if it doesn't, this function does nothing.
remove_scheduled_function (item)
Unschedule a function. This is useful for cancelling a rollback of a completed operation.

Parameters

  • 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.
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.

Return value:

table: A token representing the scheduled execution, which can be used to remove the item later from the list.
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.

Valid XHTML 1.0!