basic set-up of actions in context with action-spec
This commit is contained in:
parent
367f5ae589
commit
645f008362
2 changed files with 15 additions and 5 deletions
|
@ -29,16 +29,24 @@
|
|||
(timestamp)
|
||||
(data)))
|
||||
|
||||
;;;; actions
|
||||
|
||||
(defclass action-spec ()
|
||||
((pattern :initarg :pattern :initform nil)
|
||||
(handlers :reader handlers :initarg :handlers)))
|
||||
|
||||
;;;; context
|
||||
|
||||
(defclass context ()
|
||||
((name :reader name :initarg :name)
|
||||
(action-handlers :accessor action-handlers :initform nil)))
|
||||
(actions :accessor actions :initform nil)))
|
||||
|
||||
(defgeneric send (rcvr msg)
|
||||
(:method ((rcvr context) msg)
|
||||
(let ((hdlrs (action-handlers rcvr)))
|
||||
(funcall (car hdlrs) msg))))
|
||||
(let* ((acts (actions rcvr))
|
||||
(selected (car acts))
|
||||
(hdlr (car (handlers selected))))
|
||||
(funcall hdlr msg))))
|
||||
|
||||
(defvar *context* nil)
|
||||
|
||||
|
@ -48,7 +56,9 @@
|
|||
(format t "~&~s~%" msg))
|
||||
|
||||
(defclass printer (context)
|
||||
((action-handlers :initform (list #'do-print))))
|
||||
((actions :initform
|
||||
(list (make-instance 'action-spec
|
||||
:handlers (list #'do-print))))))
|
||||
|
||||
(defun printer (name)
|
||||
(make-instance 'printer :name name))
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
(defclass test-suite (t:test-suite)
|
||||
((receiver :reader receiver
|
||||
:initform (core:printer :test-rcvr))))
|
||||
;:initform (make-instance 'core:context :name :test-rcvr))))
|
||||
;:initform (make-instance 't:test-rcvr))))
|
||||
|
||||
(defun run ()
|
||||
(let ((*config* nil)
|
||||
|
|
Loading…
Add table
Reference in a new issue