From 6ae79a48d55377aacb67af0b6a2f76d5692a24ae Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Fri, 11 Jan 2019 09:26:34 +0000 Subject: [PATCH] New modopts.js usage supported: You may now request the value of a single modopts.ini key value (optionally specifying a default option value), via: optval = load({}, 'modopts.js', 'modname', 'optname'); or: optval = load({}, 'modopts.js', 'modname', 'optname', default_optval); This usage will return just a single option value rather than an object containing properties reflecting all the options in the [modname] section. The pre-existing usage is still supported (and preferred in most cases). --- exec/load/modopts.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/exec/load/modopts.js b/exec/load/modopts.js index f2cb4d28e6..117383d772 100644 --- a/exec/load/modopts.js +++ b/exec/load/modopts.js @@ -12,19 +12,26 @@ options=load(new Object, "modopts.js", "your_module_name"); */ +// Another valid use is to request the value of a single module option, like this: +// opt_value = load({}, "modopts.js", "your_module", "opt_name"); +// or: +// opt_value = load({}, "modopts.js", "your_module", "opt_name", default_opt_value); -function get_mod_options(modname) +"use strict"; +function get_mod_options(modname, optname, default_optval) { var ini_file = new File(file_cfgname(system.ctrl_dir, "modopts.ini")); if(!ini_file.open("r")) { - delete ini_file; return undefined; } - var obj = ini_file.iniGetObject(modname); + var val; + if(optname) // Get a specific option value (optionally, with default value) + val = ini_file.iniGetValue(modname, optname, default_optval); + else // Get all options + val = ini_file.iniGetObject(modname); ini_file.close(); - delete ini_file; - return obj; + return val; } -get_mod_options(argv[0]); \ No newline at end of file +get_mod_options(argv[0], argv[1], argv[2]); \ No newline at end of file -- GitLab