Skip to content
Awful Toolbox
Config

Awful Config

Some users may wish to store certain things in between reloads or per character. This can be accomplished by using the awful.config method.

A basic example to save any type of data:

local Unlocker, awful, projectName = ...

-- create the config file within awful
local config = awful.NewConfig("projectName")

-- use that config file globally
projectName.config = config

-- in another file you can use, or add to the config
local config = projectName.config

-- such as storing a position for a widget frame you create
config.savedPos = {
    point = "CENTER",
    x = 0,
    y = 0,
}

For example if you'd like to store config options per character this is what you would do:

local Unlocker, awful, projectName = ...

local name, realm = UnitFullName("player")
local config = awful.NewConfig('project' .. name .. realm)

-- any primitive type or table containing primitive types can be persisted in config
config.savedBool = true
config.savedInt = 123
config.savedArray = { 
    123,
    'abc',
    true,
    false
}
config.savedAssociativeArray = {
    cats = "cool",
    dogs = "drool" 
}

-- reference types like functions can technically be stored in
-- a config table, but will not persist through reloads as
-- the value behind it is just a temporary memory address
config.savedFunction = function(...)
    print('args:', ...)
end
-- this redeclaration is required on load for the function to retain its functionality

Triggering a Save

Any shallow write to the config will trigger a config save, for example:


-- config.savedVar value is updated and saved to persist through reloads and restarts
config.savedVar = true

-- config.newSavedTable is updated and saved to persist
config.newSavedTable = { 'a', 'b' }

-- config.newSavedTable is updated for the current session, but is NOT saved and will not persist
table.insert(config.newSavedTable, 'c')

-- you must do a shallow write to the config table to save and persist
local function insertSubConfigValue(key, value)
    -- nested write
    tinsert(config[key], value)

    -- shallow write saves and persists
    config[key] = config[key]
end

-- saves and persists
insertSubConfigValue("newSavedTable", 'c')
Last updated on December 8, 2022