Module luarocks.persist

Utility module for loading files into tables and saving tables into files. Implemented separately to avoid interdependencies, as it is used in the bootstrapping stage of the cfg module.

Functions

load_into_table (filename, tbl) Load a Lua file containing assignments, storing them in a table.
save_from_table (filename, tbl) Save the contents of a table in a file.
write_table (out, tbl) Write a table as Lua code representing a table to disk (that is, in curly brackets notation).


Functions

load_into_table (filename, tbl)
Load a Lua file containing assignments, storing them in a table. The global environment is not propagated to the loaded file.

Parameters

  • filename: string: the name of the file.
  • tbl: table or nil: if given, this table is used to store loaded values.

Return value:

table or (nil, string): a table with the file's assignments as fields, or nil and a message in case of errors.
save_from_table (filename, tbl)
Save the contents of a table in a file. Each element of the table is saved as a global assignment. Only numbers, strings and tables (containing numbers, strings or other recursively processed tables) are supported.

Parameters

  • filename:
  • tbl:

Return value:

boolean or (nil, string): true if successful, or nil and a message in case of errors.
write_table (out, tbl)
Write a table as Lua code representing a table to disk (that is, in curly brackets notation). This function handles only numbers, strings and tables are keys (tables are handled recursively).

Parameters

  • out: userdata: a file object, open for writing.
  • tbl: table: the table to be written.

Valid XHTML 1.0!