Software /
code /
prosody
Diff
core/moduleapi.lua @ 13201:65fb0d7a2312
moduleapi: Add enum config option method
For when a setting has a few fixed values it can take
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 16 Jan 2021 20:40:14 +0100 |
parent | 13016:8aec903ea888 |
child | 13203:aa6c2692a4be |
line wrap: on
line diff
--- 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 });