Module luarocks.util
Functions
deep_merge (dst, src) | Merges contents of src on top of dst's contents. |
keys (tbl) | Return an array of keys of a table. |
make_shallow_copy (tbl) | Create a new shallow copy of a table: a new table with the same keys and values. |
parse_flags (...) | Extract flags from an arguments list. |
platform_overrides (tbl) | Perform platform-specific overrides on a table. |
printerr (...) | Print a line to standard error |
printout (...) | Print a line to standard output |
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. |
sortedpairs (tbl, sort_function) | A table iterator generator that returns elements sorted by key, to be used in "for" loops. |
variable_substitutions (tbl, vars) | Perform make-style variable substitutions on string values of a table. |
warning (msg) | Display a warning message. |
Functions
- 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:
- keys (tbl)
-
Return an array of keys of a table.
Parameters
- tbl: table: The input table.
Return value:
table: The array of keys. - make_shallow_copy (tbl)
-
Create a new shallow copy of a table: a new table with the same keys and values. Keys point to the same objects as the original table (ie, does not copy recursively).
Parameters
- tbl: table: the input table
Return value:
table: a new table with the same contents. - 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
- ...:
- 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.
- printerr (...)
-
Print a line to standard error
Parameters
- ...:
- printout (...)
-
Print a line to standard output
Parameters
- ...:
- remove_scheduled_function (item)
-
Unschedule a function. This is useful for cancelling a rollback of a completed operation.
Parameters
- item: table: The token representing the scheduled function that was returned from the schedule_function call.
- 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. - 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.
Return value:
function: the iterator function. - 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.
- warning (msg)
-
Display a warning message.
Parameters
- msg: string: the warning message