settings#
local settings = require 'settings'
The settings
module can be used to create and read settings files,
which are stored in the settings
folder as JSON files. Modules can have
multiple settings objects, and therefore files.
Functions#
- settings.new(name)#
Creates a new
settings.settings
object. If the corresponding JSON file does not exist it will be created.- Parameters:
name (
string
) – The name of the settings object and corresponding file.- Returns:
A new settings object
- Return type:
Note
While not strictly required, module authors are encouraged to name settings after the module that creates them, ie console.lua.
Version History
Version
Notes
0.0.1
Added
Classes#
- class settings.settings#
A settings object.
- set(key, value)#
Set the value for the given key. If the key already exists it will be overridden.
- Parameters:
key (
string
) – The key to set.value (number, boolean, nil, string, or
jansson.json
) – The value to set. Tables are not supported, objects or arrays should be passed asjansson.json
objects instead.
Version History
Version
Notes
0.0.1
Added
- setdefault(key, value)#
Set a default value for a given key. This functions exactly like
settings.set()
except this does not write the value to the underlying JSON file.- Parameters:
key (
string
) – The key to set.value (number, boolean, nil, string, or
jansson.json
) – The value to set. Tables are not supported, objects or arrays should be passed asjansson.json
objects instead.
Version History
Version
Notes
0.0.1
Added
- get(key)#
Get the value for the given key. If the key doesn’t exist, return the default value, if set. If not, returns
nil
.Object and arrays are returned as
jansson.json
objects.- Parameters:
key (
string
) – The key to return. This is a path into the JSON object structure separated by.
. I.e.window.x
.- Returns:
The config value at
key
ornil
Version History
Version
Notes
0.0.1
Added
- saveonset(value)#
Control the behvior when setting a value. By default,
settings.settings
will save values to the underlying JSON file every time a value is set. This behavior can be turned off by passingfalse
to this function.- Parameters:
value – Save on set?
Version History
Version
Notes
0.0.1
Added
- save()#
Save the
settings.settings
object to the underlying JSON file. This is required ifsaveonset()
is turned off.Version History
Version
Notes
0.0.1
Added