-- requiredArguments is a set of keys that must be mapped to non-nil values in arguments
-- optionalArguments is a mapping of optional keys in arguments to their default values

return function(arguments, requiredArguments, optionalArguments)
	for key, _ in pairs(requiredArguments) do
		if arguments[key] == nil then
			error("Did not provide required argument " .. key)
		end
	end

	if optionalArguments then
		for key, defaultValue in pairs(optionalArguments) do
			if arguments[key] == nil then
				arguments[key] = defaultValue
			end
		end
	end

	for key in pairs(arguments) do
		if requiredArguments[key] == nil and ((not optionalArguments) or optionalArguments[key] == nil) then
			error("Provided invalid argument " .. key)
		end
	end
end
