Library

settings

table

Namespaced configuration with schema-validated entries. Each namespace registers its keys, types, defaults and validators once; reads are cheap and writes notify watchers synchronously.

Functions

8

#settings.register(namespace: string, schema: table) → table

since 1.8.3-free

Registers a settings namespace with a schema and returns a proxy table for typed access.

Parameters

namespacestring

The namespace name (e.g. user.myscript). Reserved prefixes (core., window., service.) are forbidden.

schematable

Map of key -> { type=string, default=any, description=string, [min=number, max=number, enum=table, readonly=boolean] }.

Returns

table

Proxy with __index/__newindex sugar; reads call settings.get(fqn), writes call settings.set(fqn, value).

Errors

  • LuaError schema invalid -- Schema rejected; key was not a string, key contained reserved characters, or a per-entry validation message was returned.

#settings.get(fqn: string) → any

since 1.8.3-free

Reads the current value of a setting.

Parameters

fqnstring

Fully-qualified name (e.g. user.myscript.foo).

#settings.set(fqn: string, value: any) → any

since 1.8.3-free

Sets a setting value. Type and range/enum validated against the schema; failure errors.

Parameters

fqnstring

Fully-qualified name.

valueany

New value.

Errors

  • LuaError validation failed -- New value failed the registered schema validator.

#settings.reset(fqn: string) → any

since 1.8.3-free

Resets a setting to its declared default.

Parameters

fqnstring

Fully-qualified name.

#settings.observe(fqn: string, callback: function(oldValue: any, newValue: any) -> ()) → table

since 1.8.3-free

Connects a callback to be fired (deferred) when the setting changes. Returns a connection table with :Disconnect().

Parameters

fqnstring

Fully-qualified name.

callbackfunction(oldValue: any, newValue: any) -> ()

Returns

table

Connection { Disconnect = function() end }.

#settings.get_schema(fqn: string) → table { type, default, description, readonly, [min, max, enum] }

since 1.8.3-free

Returns the schema of a setting as a table.

Aliasesgetschema

Parameters

fqnstring

Fully-qualified name.

#settings.list_namespaces() → table

since 1.8.3-free

Lists all currently-registered setting namespaces.

Aliaseslistnamespaces

Returns

table

Array of namespace name strings.

#settings.list_keys(namespace: string) → table

since 1.8.3-free

Lists all setting keys registered in a namespace.

Aliaseslistkeys

Parameters

namespacestring

Returns

table

Array of key strings.

Errors

  • LuaError unknown namespace -- No namespace registered under that name.