diff options
Diffstat (limited to 'acf/persistence/init.lua')
-rw-r--r-- | acf/persistence/init.lua | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/acf/persistence/init.lua b/acf/persistence/init.lua index de23a68..7b10002 100644 --- a/acf/persistence/init.lua +++ b/acf/persistence/init.lua @@ -29,9 +29,27 @@ function DataStore:split_path(path) return backend, comps end -function DataStore:get(path) +function DataStore:get(path, t) local backend, comps = self:split_path(path) - return util.copy(backend:get(comps)), self.mod_time[path] or 0 + local res = backend:get(comps, t) + + if t ~= nil and res ~= nil then + local atype = type(res) + + if t == 'table' then assert(atype == 'table') + + else + assert(atype ~= 'table') + + if t == 'string' then res = tostring(res) + elseif t == 'number' then res = tonumber(res) + elseif t == 'boolean' then res = res and true or false + elseif t == 'reference' then assert(atype == 'string') + else assert(false) end + end + end + + return util.copy(res), self.mod_time[path] or 0 end function DataStore:_set_multiple(mods) |