Comparison

core/moduleapi.lua @ 7982:e30b0cbed472

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Thu, 16 Mar 2017 23:49:27 +0100
parent 7950:f91e7ec9654e
parent 7975:c64ddee9d671
child 8487:91f6815de26a
comparison
equal deleted inserted replaced
7974:547f000941cf 7982:e30b0cbed472
212 value = default_value; 212 value = default_value;
213 end 213 end
214 return value; 214 return value;
215 end 215 end
216 216
217 function api:get_option_string(name, default_value) 217 function api:get_option_scalar(name, default_value)
218 local value = self:get_option(name, default_value); 218 local value = self:get_option(name, default_value);
219 if type(value) == "table" then 219 if type(value) == "table" then
220 if #value > 1 then 220 if #value > 1 then
221 self:log("error", "Config option '%s' does not take a list, using just the first item", name); 221 self:log("error", "Config option '%s' does not take a list, using just the first item", name);
222 end 222 end
223 value = value[1]; 223 value = value[1];
224 end 224 end
225 return value;
226 end
227
228 function api:get_option_string(name, default_value)
229 local value = self:get_option_scalar(name, default_value);
225 if value == nil then 230 if value == nil then
226 return nil; 231 return nil;
227 end 232 end
228 return tostring(value); 233 return tostring(value);
229 end 234 end
230 235
231 function api:get_option_number(name, ...) 236 function api:get_option_number(name, ...)
232 local value = self:get_option(name, ...); 237 local value = self:get_option_scalar(name, ...);
233 if type(value) == "table" then
234 if #value > 1 then
235 self:log("error", "Config option '%s' does not take a list, using just the first item", name);
236 end
237 value = value[1];
238 end
239 local ret = tonumber(value); 238 local ret = tonumber(value);
240 if value ~= nil and ret == nil then 239 if value ~= nil and ret == nil then
241 self:log("error", "Config option '%s' not understood, expecting a number", name); 240 self:log("error", "Config option '%s' not understood, expecting a number", name);
242 end 241 end
243 return ret; 242 return ret;
244 end 243 end
245 244
246 function api:get_option_boolean(name, ...) 245 function api:get_option_boolean(name, ...)
247 local value = self:get_option(name, ...); 246 local value = self:get_option_scalar(name, ...);
248 if type(value) == "table" then
249 if #value > 1 then
250 self:log("error", "Config option '%s' does not take a list, using just the first item", name);
251 end
252 value = value[1];
253 end
254 if value == nil then 247 if value == nil then
255 return nil; 248 return nil;
256 end 249 end
257 local ret = value == true or value == "true" or value == 1 or nil; 250 local ret = value == true or value == "true" or value == 1 or nil;
258 if ret == nil then 251 if ret == nil then