core/moduleapi.lua
changeset 13205 65fb0d7a2312
parent 13020 8aec903ea888
child 13207 aa6c2692a4be
--- a/core/moduleapi.lua	Sun Jul 16 20:29:06 2023 +0200
+++ b/core/moduleapi.lua	Sat Jan 16 20:40:14 2021 +0100
@@ -310,6 +310,15 @@
 	return resolve_relative_path(parent, value);
 end
 
+function api:get_option_enum(name, default, ...)
+	local value = self:get_option_scalar(name, default);
+	if value == nil then return nil; end
+	local options = set.new{default, ...};
+	if not options:contains(value) then
+		self:log("error", "Config option '%s' not in set of allowed values (one of: %s)", name, options);
+	end
+	return value;
+end
 
 function api:context(host)
 	return setmetatable({ host = host or "*", global = "*" == host }, { __index = self, __newindex = self });