Skip to content

Commit

Permalink
Sumenko reports duplicate function definitions, unsure why.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamharrison committed Apr 3, 2024
1 parent 9b25c43 commit 724fdf9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions data/core/storage.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
local core = require "core"
local common = require "core.common"

local function module_key_to_path(module, key)
return USERDIR .. PATHSEP .. "storage" .. (module and (PATHSEP .. module .. (key and (PATHSEP .. key:gsub("[\\/]", "-")) or "")) or "")
end


----- Provides persistent storage between restarts of the application.
---Provides persistent storage between restarts of the application.
---@class storage
local storage = {}

---Loads data from a persistent storage file.

---Loads data from a persistent storage file.
---
---@param module string The module under which the data is stored.
---@param key string The key under which the data is stored.
---@return string|table|number data The stored data present for this module, at this key.
---@return string|table|number? data The stored data present for this module, at this key.
function storage.load(module, key)
local path = module_key_to_path(module, key)
if system.get_file_info(path) then
Expand All @@ -29,7 +31,7 @@ end


---Saves data to a persistent storage file.

---
---@param module string The module under which the data is stored.
---@param key string The key under which the data is stored.
---@param value table|string|number The value to store.
Expand All @@ -53,16 +55,16 @@ end


---Gets the list of keys saved under a module.

---
---@param module string The module under which the data is stored.
---@return table A table of keys under which data is stored for this module.
function storage.keys(module)
return system.list_dir(module_key_to_path(module))
return system.list_dir(module_key_to_path(module)) or {}
end


---Clears data for a particular module and optionally key.

---
---@param module string The module under which the data is stored.
---@param key? string The key under which the data is stored. If omitted, will clear the entire store for this module.
function storage.clear(module, key)
Expand All @@ -72,4 +74,5 @@ function storage.clear(module, key)
end
end


return storage

0 comments on commit 724fdf9

Please sign in to comment.