Commit 06adb891 authored by Marek Vavruša's avatar Marek Vavruša

daemon: added config syntax sugar for ‘modules’

example:
modules.hints = ‘{“input”:”/etc/hosts”}’
.. is equal to ..
modules.load(‘hints’)
hints.config(‘{“input”:”/etc/hosts”}’)
parent abbd5e58
...@@ -8,7 +8,7 @@ kresolved_SOURCES := \ ...@@ -8,7 +8,7 @@ kresolved_SOURCES := \
daemon/main.c daemon/main.c
# Embed resources # Embed resources
daemon/engine.o: daemon/lua/init.inc daemon/engine.o: daemon/lua/init.inc daemon/lua/config.inc
%.inc: %.lua %.inc: %.lua
@$(call quiet,XXD,$<) -i < $< > $@ @$(call quiet,XXD,$<) -i < $< > $@
@echo ', 0x00' >> $@ @echo ', 0x00' >> $@
......
-- Default configuration
cache.open('.', 10485760)
-- Default configuration -- Syntactic sugar for module loading
cache.open('.', 10485760) -- `modules.<name> = <config>`
local modules_mt = {
__newindex = function (t,k,v)
modules.load(k)
_G[k]['config'](v)
end
}
setmetatable(modules, modules_mt)
\ No newline at end of file
...@@ -36,18 +36,23 @@ struct kr_prop; ...@@ -36,18 +36,23 @@ struct kr_prop;
typedef uint32_t (module_api_cb)(void); typedef uint32_t (module_api_cb)(void);
typedef int (module_init_cb)(struct kr_module *); typedef int (module_init_cb)(struct kr_module *);
typedef int (module_deinit_cb)(struct kr_module *); typedef int (module_deinit_cb)(struct kr_module *);
typedef int (module_config_cb)(struct kr_module *, void *); typedef int (module_config_cb)(struct kr_module *, const char *);
typedef const knot_layer_api_t* (module_layer_cb)(void); typedef const knot_layer_api_t* (module_layer_cb)(void);
typedef struct kr_prop *(module_prop_cb)(void); typedef struct kr_prop *(module_prop_cb)(void);
#define KR_MODULE_API ((uint32_t) 0x20150401) #define KR_MODULE_API ((uint32_t) 0x20150401)
/**
* Property callback.
*/
typedef char *(kr_prop_cb)(void *, struct kr_module *, const char *);
/** /**
* Module property (named callable). * Module property (named callable).
* A module property has a free-form JSON output (and optional input). * A module property has a free-form JSON output (and optional input).
*/ */
struct kr_prop { struct kr_prop {
char *(*cb)(void *, struct kr_module *, const char *); kr_prop_cb *cb;
const char *name; const char *name;
const char *info; const char *info;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment