mjolnir._asm.settings

Home: https://github.com/asmagill/mjolnir_asm.sys

Functions for manipulating user defaults for the Mjolnir application, allowing for the creation of user-defined settings which persist across Mjolnir launches and reloads. Settings must have a string key and must be made up of serializable Lua objects (string, number, boolean, nil, tables of such, etc.)

This module is based partially on code from the previous incarnation of Mjolnir by Steven Degutis.

This module also requires mjolnir._asm for NSObject traversal.

clear

mjolnir._asm.settings.clear(key) -> bool

Attempts to remove the given string key from storage, returning true on success or false on failure (e.g. key does not exist or is administratively managed).

get

mjolnir._asm.settings.get(key) -> val

Gets the Lua value for the given string key. This function can retrieve NSUserDefault types of Data and Date, as well as serializable Lua types.

getkeys

mjolnir._asm.settings.getkeys() -> []

Returns a table of all defined keys within the Mjolnir user defaults, as an array and as a list of keys. Use ipairs(settings.getkeys()) to iterate through the list of all settings which have been defined or settings.getkeys()["key"] to test for the existence of a key.

set

mjolnir._asm.settings.set(key, val)

Saves the given value for the given string key; value must be a string, number, boolean, nil, or a table of any of these, recursively. This function cannot set NSUserDefault types of Data or Date. See settings.set_data and settings.set_date.

set_data

mjolnir._asm.settings.set_data(key, val)

Saves the given value as raw binary data for the string key. A raw binary string differs from a traditional string in that it may contain embedded null values and other unprintable bytes (characters) which might otherwise be lost or mangled if treated as a traditional C-Style (null terminated) string.

set_date

mjolnir._asm.settings.set_date(key, val)

Saves the given value as a date for the given string key. If val is a number, then it represents the number of seconds since 1970-01-01 00:00:00 +0000 (e.g. os.time()). If it is a string, it should be in the format of 'YYYY-MM-DD HH:MM:SS ±HHMM' (e.g. os.date("%Y-%m-%d %H:%M:%S %z")).