modlib/persistence.lua

23 lines
663 B
Lua
Raw Permalink Normal View History

local require = ... or require
2021-07-14 21:52:13 +02:00
-- TODO consider moving serializers in this namespace
local function load(module_name)
return assert(loadfile(modlib.mod.get_resource(modlib.modname, "persistence", module_name .. ".lua")))
end
2022-02-27 17:41:25 +01:00
return setmetatable({}, {__index = function(self, module_name)
2021-07-14 21:52:13 +02:00
if module_name == "lua_log_file" then
local module = load(module_name)()
2022-02-27 17:41:25 +01:00
self[module_name] = module
2021-07-14 21:52:13 +02:00
return module
end
if module_name == "sqlite3" then
local func = load(module_name)
local module = function(sqlite3)
if sqlite3 then
return func(sqlite3)
end
return func(require"lsqlite3")
end
2022-02-27 17:41:25 +01:00
self[module_name] = module
2021-07-14 21:52:13 +02:00
return module
end
2022-02-27 17:41:25 +01:00
end})