init.lua 648 Bytes
Newer Older
1 2
-- Syntactic sugar for module loading
-- `modules.<name> = <config>`
3
setmetatable(modules, {
4 5
	__newindex = function (t,k,v)
		modules.load(k)
6 7 8 9 10 11
		if _G[k] then
			local config_call = _G[k]['config']
			if config_call and config_call[''] then
				config_call(v)
			end
		end
12
	end
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
})

-- Some services are append-only
function protect(defined)
	local __protected = { ['modules'] = true }
	return setmetatable({}, {
		__index = defined,
		__newindex = function (t, k, v)
			if __protected[k] then
				for k2,v2 in pairs(v) do
					defined[k][k2] = v2
				end
			else
				defined[k] = v
			end
		end
	})
end
31 32
-- _G = protect(getfenv(0))
-- setfenv(0, _G)