Comparison

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
comparison
equal deleted inserted replaced
13200:150e3bbec1bd 13201:65fb0d7a2312
308 return nil; 308 return nil;
309 end 309 end
310 return resolve_relative_path(parent, value); 310 return resolve_relative_path(parent, value);
311 end 311 end
312 312
313 function api:get_option_enum(name, default, ...)
314 local value = self:get_option_scalar(name, default);
315 if value == nil then return nil; end
316 local options = set.new{default, ...};
317 if not options:contains(value) then
318 self:log("error", "Config option '%s' not in set of allowed values (one of: %s)", name, options);
319 end
320 return value;
321 end
313 322
314 function api:context(host) 323 function api:context(host)
315 return setmetatable({ host = host or "*", global = "*" == host }, { __index = self, __newindex = self }); 324 return setmetatable({ host = host or "*", global = "*" == host }, { __index = self, __newindex = self });
316 end 325 end
317 326