diff options
Diffstat (limited to 'src/daemon/sample-config/common.cfg')
-rw-r--r-- | src/daemon/sample-config/common.cfg | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/daemon/sample-config/common.cfg b/src/daemon/sample-config/common.cfg new file mode 100644 index 0000000..a8e88ab --- /dev/null +++ b/src/daemon/sample-config/common.cfg @@ -0,0 +1,56 @@ +-- -*- mode: lua -*- + +-- plugin optionality constants +OPTIONAL = 1 -- mark a plugin optional +IFEXISTS = 2 -- mark a plugin mandatory if present +MANDATORY = 3 -- mark a plugin mandatory + +-- function to try loading an optional plugin, ignoring errors +function try_load(plugin, ...) + local a = {...} + m:info('* Trying to load (optional) plugin ' .. plugin) + if #a == 0 then return m:try_load_plugin(plugin ) + elseif #a == 1 then return m:try_load_plugin(plugin, a[1] ) + else return m:try_load_plugin(plugin, a[1], a[2]) + end +end + +-- function to load a plugin if it exists +function load_if_exists(plugin, ...) + local a = {...} + if m:plugin_exists(plugin) then + m:info('* Loading (existing) plugin ' .. plugin) + else + return true + end + if #a == 0 then return m:load_plugin(plugin ) + elseif #a == 1 then return m:load_plugin(plugin, a[1] ) + else return m:load_plugin(plugin, a[1], a[2]) + end +end + +-- function to load a mandatory plugin +function load(plugin, ...) + local a = {...} + m:info('* Loading (mandatory) plugin ' .. plugin) + if #a == 0 then return m:load_plugin(plugin ) + elseif #a == 1 then return m:load_plugin(plugin, a[1] ) + else return m:load_plugin(plugin, a[1], a[2]) + end +end + +-- function to check if a plugin has been successfully loaded (and running) +function loaded(plugin) + return m:plugin_loaded(plugin) +end + +-- function to include a file +function include(file, necessity) + if necessity < MANDATORY then + m:info('* Trying to include (optional) ' .. file) + m:try_include(file) + else + m:info('* Including (mandatory) ' .. file) + m:include(file) + end +end |