Module:Loader

From Chalo Chatu, Zambia online encyclopedia

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