Child pages
  • Settings Framework
Skip to end of metadata
Go to start of metadata

The settings module is used to read and write system settings.

Settings are stored on the Filesystem as string based key/value pairs. Parameters of a settings are:

ParameterDescription
ID"dot-separated" name (e.g. "network.ip.netmask")
LabelDisplayed name of the settings (e.g. "Subnetmask")
TypeArbitrary string defining the type (e.g. "ip_address" )
ValueString with the value of the setting (e.g. "255.255.255.0" )
EditableBoolean value indicating if the settings can be changed or not

Settings are organized in a tree structure. Each node has a name of at most 8 characters (case insensitive, numbers and letters only, no spaces or special characters allowed). The ID of a settings is a concatenation of the IDs of the nodes in its "path" down the tree.

E.g.

  • network
  • network.ip
  • network.ip.netmask
  • network.ip.gateway

Learn more, go to page The Settings Framework

Functions

FunctionDescription
.create( id, label, type, value, editable)Creates a setting.
.read( id )Reads the value of a setting.
.write( id, value )

Writes the value of a setting.

.delete( id )Deletes a setting.

 .create( id, label, type, value, editable)

Creates a setting. If the setting already exists the string "Exists" is returned and the setting is not updated with the provided value.

ParameterTypeDescription
idStringThe ID of the settings. Must be a valid "dot-separated" ID.
labelStringThe label of the settings used for displaying.
typeStringThe type of settings. This is an arbitrary string.
valueStringThe content of the setting. This is always a string.
editableBooleanMake the setting editable or not.
Return ValueTypeDescription
errorString Error string describing the issue (e.g. "Exists" or nil when the operation was successful.
Example: Creating a setting
-- Create a clean looking title "Network Settings".
err = settings.create("network", "Network Settings", nil, "", true)


-- Create a Subnetmask under the "network" title. 
err = settings.create( 
		"network.ip.netmask",
		"Subnetmask",
		"ip_address",
		"255.255.255.0",
		true
		)

Adding a title

On the Lua Development Environment webpage you can view and edit these settings by clicking on the "settings"-icon. 

Creating a hidden setting

A hidden setting can be created by starting the id with an underscore.

.read( id )

Reads the value of a setting. Returns the string value of a setting. In case an error occures during reading (e.g. setting does not exist) nil is returned together with a second string with error information.

ParameterTypeDescription
idStringThe ID of the settings. Must be a valid "dot-separated" ID.
Return ValueTypeDescription
valueStringValue of the setting or nil if the settings could not be read.
errorStringError string describing the issue or nil when the operation was successful.
Example: Reading a setting
value, err = settings.read( "network.ip.netmask" )

.write( id, value )

 Writes the value of a setting. Updates the setting to the value that is provided. In case an error occurs during writing (e.g. setting does not exist) an error string is returned.

ParameterTypeDescription
idStringThe ID of the settings. Must be a valid "dot-separated" ID.
valueStringThe new content of the setting. This is always a string.
Return ValueTypeDescription
errorStringError string describing the issue or nil when the operation was successful.
Example: Writing a setting
err = settings.write( "network.ip.netmask", "255.255.0.0" )

.delete( id )

Deletes a setting. If the setting has children these are also deleted. In case an error occurs during writing (e.g. setting does not exist) an error string is returned.

ParameterTypeDescription
idStringThe ID of the settings. Must be a valid "dot-separated" ID.
Return ValueTypeDescription
errorString Error string describing the issue or nil when the operation was successful.
Example: Deleting a setting
-- Given the settings from the example above, below command will delete the following settings:
--   network
--   network.ip
--   network.ip.netmask
--   network.ip.gateway

err = settings.delete( "network" )
  • No labels