Skip to content

storage.read

since 1.1.0

Read a value from the current storage.

storage.read(label)

Parameters

Name Type Required Description
label string yes

Returns

The value read

Examples

local function read(widget)
  widget.source = storage.read("source")            -- a saved Source comes back as a Source
  widget.threshold = storage.read("threshold") or 33 -- default for widgets saved by an older version
end

Use it inside read callbacks of widgets, tasks and sources. Values live in the model file. See Saving settings.

Used in

Real-world usage

Called 16 times across 3 open-source Ethos Lua projects. A few short excerpts:
widget.pumpSource = storage.read("pumpSource")

lua/frsky/JetWidget/main.lua:376

local function read(widget)
    widget.discIdx    = storage.read("discIdx")    or widget.discIdx
    widget.certIdx    = storage.read("certIdx")    or widget.certIdx
    widget.trigSwitch = storage.read("trigSwitch") or widget.trigSwitch
    widget.rstSwitch  = storage.read("rstSwitch")  or widget.rstSwitch
    widget.repSwitch  = storage.read("repSwitch")  or widget.repSwitch
end

src/bmfa-caller/widget_impl.lua:153

function widget.read()
    local storedPage = storage.read("currentPage")
    if storedPage then
        currentPage = tonumber(storedPage)
    else
        currentPage = 1
    end
end

src/inav-dashboard/widget.lua:412