summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2014-12-11 20:48:13 +0100
committerrekado <rekado@elephly.net>2014-12-11 20:48:13 +0100
commit58dd0d498899e4f6d5ae2a67504bce620c20c823 (patch)
treed1a889f69ff9ef4aa210c1c17ccda3f5b44fa195
parentb2d20af884f494fc5178659663ff7d52046fe179 (diff)
convert register-stanza-handler to syntax
allow omitting guard expression.
-rw-r--r--xmpp.scm13
1 files changed, 10 insertions, 3 deletions
diff --git a/xmpp.scm b/xmpp.scm
index 1e91713..546edfc 100644
--- a/xmpp.scm
+++ b/xmpp.scm
@@ -20,10 +20,17 @@
(define *stanza-handlers* '())
(define *stanza-id-handlers* (make-hash-table))
-(define (register-stanza-handler predicate handler)
- "Register handler function that will be executed when a stanza is
+(define-syntax register-stanza-handler
+ (lambda (s)
+ "Register handler function that will be executed when a stanza is
encountered that matches the given predicate."
- (set! *stanza-handlers* (cons `(,predicate . ,handler) *stanza-handlers*)))
+ (syntax-case s ()
+ ((_ guard handler)
+ (if (eqv? #t (syntax->datum #'guard))
+ #'(set! *stanza-handlers* (cons `(,(lambda _ #t) . ,handler) *stanza-handlers*))
+ #'(set! *stanza-handlers* (cons `(,guard . ,handler) *stanza-handlers*))))
+ ((_ handler)
+ #'(set! *stanza-handlers* (cons `(,(lambda _ #t) . ,handler) *stanza-handlers*))))))
(define (register-temp-stanza-handler-for-id stanza-id handler)
"Register handler function that will be executed when a stanza with