Config module

For working with mod configurations.

Usage

require('stdlib/config/config')

Functions

delete (path) Delete a stored config value.
get (path[, default]) Get a stored config value.
is_set (path) Test the existence of a stored config value.
new (config_table) Creates a new Config object to ease the management of a config table.
set (path, data) Set a stored config value.

Tables

Config

Functions

# delete (path)

Delete a stored config value.

Parameters:
  • path : (string) the config path to delete
Returns:
  • (uint) 0 on failure or the number of affected paths on success
# get (path[, default])

Get a stored config value.

Parameters:
  • path : (string) the variable to retrieve
  • default : (Mixed) value to be used if path is nil (optional)
Returns:
  • (Mixed) value at path or nil if not found and no default given
# is_set (path)

Test the existence of a stored config value.

Parameters:
  • path : (string) the config path to test
Returns:
  • (boolean) true if the value exists, false otherwise
# new (config_table)

Creates a new Config object to ease the management of a config table.

Parameters:
  • config_table : (table) the config table to manage
Returns:
  • (Config) the Config object to manage the config table
Usage:
--[Use a global table for config that persists across game save/loads]
CONFIG = Config.new(global.testtable)
--[You can also create a temporary scratch pad config]
CONFIG = Config.new({}) -- Temporary scratch pad
--[Setting data in Config]
CONFIG = Config.new(global.testtable)
CONFIG.set("your.path.here", "myvalue")
--[Getting data out of Config]
CONFIG = Config.new(global.testtable)
my_data = CONFIG.get("your.path.here")
--[Getting data out of Config with a default to use if path is not found in Config]
CONFIG = Config.new(global.testtable)
my_data = CONFIG.get("your.path.here", "Your Default here")
--[Deleting a path from Config]
CONFIG = Config.new(global.testtable)
CONFIG.delete("your.path.here")
--[Checking if a path exists in Config]
CONFIG = Config.new(global.testtable)
CONFIG.is_set("your.path.here")
# set (path, data)

Set a stored config value.

Parameters:
  • path : (string) the config path to set
  • data : (nil or Mixed) the value to set the path to. If nil, it behaves identical to Config.delete()
Returns:
  • (uint) 0 on failure or the number of affected paths on success

Tables

# Config
Fields: