diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-04-03 22:07:31 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-04-03 22:07:31 +0200 |
commit | 768d677474619922acd934befece78ce84c4ca0e (patch) | |
tree | 3d93f0ab5cf20a60f90fa4a5a0ff0bfdae87df39 /module | |
parent | Enable REPL server in main. (diff) | |
download | calp-768d677474619922acd934befece78ce84c4ca0e.tar.gz calp-768d677474619922acd934befece78ce84c4ca0e.tar.xz |
Update define-config to hopefully check pre-existing values.
Diffstat (limited to '')
-rw-r--r-- | module/util/config.scm | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/module/util/config.scm b/module/util/config.scm index 68758ad0..98582b7c 100644 --- a/module/util/config.scm +++ b/module/util/config.scm @@ -30,16 +30,25 @@ ;; TODO possibly make @var{documentation} and @var{valid-value?} optional. (define-macro (define-config name default-value documentation valid-value?) `(let ((make-config (@@ (util config) make-config)) - (config-values (@@ (util config) config-values))) + (config-values (@@ (util config) config-values)) + (config? (@@ (util config) config?)) + (get-value (@@ (util config) get-value))) (cond [(hashq-ref config-values (quote ,name)) => (lambda (value) + ;; When reloading a module an already defined configuration item + ;; might be loaded again, just anwrap it and pretend that didn't + ;; happen. + (when (,config? value) + (set! value (,get-value value))) + (unless (,valid-value? value) - (throw 'config-error - "Config [~a]: ~a doesn't sattisfy predicate ~s~%\"~a\"~%" - (quote ,name) - value - ,valid-value? - ,documentation)) + (scm-error 'config-error 'define-config + "Config [~a]: ~a doesn't sattisfy predicate ~s~%\"~a\"~%" + (list (quote ,name) + value + ,valid-value? + ,documentation) + (list value))) (hashq-set! config-values (quote ,name) (make-config value ,documentation ,valid-value? (current-module))))] |