function Config.new(T)local S={}S.defaultConfig=T S.defaultConfigKeys={}for T in pairs(T)do table.insert(S.defaultConfigKeys,T)end S._currentConfig=setmetatable({},{__index=function(T,E)local u=("\073\110\118\097\108\105\100 \103\108\111\098\097\108 \099\111\110\102\105\103\117\114\097\116\105\111\110 \107\101\121 \037\113\046 \086\097\108\105\100 \099\111\110\102\105\103\117\114\097\116\105\111\110 \107\101\121\115 \097\114\101\058 \037\115"):format(tostring(E),table.concat(S.defaultConfigKeys,"\044 "))error(u,3)end})S.set=function(...)return Config.set(S,...)end S.get=function(...)return Config.get(S,...)end S.scoped=function(...)return Config.scoped(S,...)end S.set(T)return S end function Config.set(S,T)for T,E in pairs(T)do if S.defaultConfig[T]==nil then local E=("\073\110\118\097\108\105\100 \103\108\111\098\097\108 \099\111\110\102\105\103\117\114\097\116\105\111\110 \107\101\121 \037\113 \040\116\121\112\101 \037\115\041\046 \086\097\108\105\100 \099\111\110\102\105\103\117\114\097\116\105\111\110 \107\101\121\115 \097\114\101\058 \037\115"):format(tostring(T),typeof(T),table.concat(S.defaultConfigKeys,"\044 "))error(E,3)end if typeof(E)~="\098\111\111\108\101\097\110"then local S=("\073\110\118\097\108\105\100 \118\097\108\117\101 \037\113 \040\116\121\112\101 \037\115\041 \102\111\114 \103\108\111\098\097\108 \099\111\110\102\105\103\117\114\097\116\105\111\110 \107\101\121 \037\113\046 \086\097\108\105\100 \118\097\108\117\101\115 \097\114\101\058 \116\114\117\101\044 \102\097\108\115\101"):format(tostring(E),typeof(E),tostring(T))error(S,3)end S._currentConfig[T]=E end end function Config.get(T)return T._currentConfig end return Config

function Config.new(defaultConfig)
	local self = {}
	self.defaultConfig = defaultConfig
	self.defaultConfigKeys = {}

	for key in pairs(defaultConfig) do
		table.insert(self.defaultConfigKeys, key)
	end

	self._currentConfig = setmetatable({}, {
		__index = function(_, key)
			local message = (
				"Invalid global configuration key %q. Valid configuration keys are: %s"
			):format(
				tostring(key),
				table.concat(self.defaultConfigKeys, ", ")
			)

			error(message, 3)
		end
	})

	-- We manually bind these methods here so that the Config's methods can be
	-- used without passing in self, since they could get exposed on the
	-- root object.
	self.set = function(...)
		return Config.set(self, ...)
	end

	self.get = function(...)
		return Config.get(self, ...)
	end

	self.scoped = function(...)
		return Config.scoped(self, ...)
	end

	self.set(defaultConfig)

	return self
end

function Config:set(configValues)
	-- Validate values without changing any configuration.
	-- We only want to apply this configuration if it's valid!
	for key, value in pairs(configValues) do
		if self.defaultConfig[key] == nil then
			local message = (
				"Invalid global configuration key %q (type %s). Valid configuration keys are: %s"
			):format(
				tostring(key),
				typeof(key),
				table.concat(self.defaultConfigKeys, ", ")
			)

			error(message, 3)
		end

		-- Right now, all configuration values must be boolean.
		if typeof(value) ~= "boolean" then
			local message = (
				"Invalid value %q (type %s) for global configuration key %q. Valid values are: true, false"
			):format(
				tostring(value),
				typeof(value),
				tostring(key)
			)

			error(message, 3)
		end

		self._currentConfig[key] = value
	end
end

function Config:get()
	return self._currentConfig
end

return Config
