Module:Loader

From Chalo Chatu, Zambia online encyclopedia
Revision as of 13:10, 22 September 2019 by Icem4k (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

local Loader = {}

function Loader.load(module, func) -- Add 'Module:' if it is missing if string.find(string.lower(module), 'module:', 1, true) ~= 1 then module = 'Module:' .. module end

if func ~= nil then return function (...) return require(module)[func](...) end end

local function doLoad(table) local result = require(module) setmetatable(table, {__index = result, __newindex = result}) end

local initialMeta = {}

function initialMeta.__index(table, key) doLoad(table) return table[key] end

function initialMeta.__newindex(table, key, value) doLoad(table) table[key] = value end

local result = {} setmetatable(result, initialMeta) return result end

return Loader