Lua load module from file

Date: 2017-08-22
local loadedModules = {}
local function loadModule(name, unload)
	if (unload) then
		loadedModules[name] = nil
	end

	if loadedModules[name] then 
		return loadedModules[name] 
	end

	local fileName = name .. '.lua'
	local moduleContent, err = loadfile(fileName)
	if (err) then
		error(string.format("error loading module: %s\r\n%s", name, err), 2);
	end
	loadedModules[name] = moduleContent() or true	
	return loadedModules[name]
end

return loadModule
8380cookie-checkLua load module from file