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)
|
(timestamp)
|
||||||
(data)))
|
(data)))
|
||||||
|
|
||||||
|
;;;; actions
|
||||||
|
|
||||||
|
(defclass action-spec ()
|
||||||
|
((pattern :initarg :pattern :initform nil)
|
||||||
|
(handlers :reader handlers :initarg :handlers)))
|
||||||
|
|
||||||
;;;; context
|
;;;; context
|
||||||
|
|
||||||
(defclass context ()
|
(defclass context ()
|
||||||
((name :reader name :initarg :name)
|
((name :reader name :initarg :name)
|
||||||
(action-handlers :accessor action-handlers :initform nil)))
|
(actions :accessor actions :initform nil)))
|
||||||
|
|
||||||
(defgeneric send (rcvr msg)
|
(defgeneric send (rcvr msg)
|
||||||
(:method ((rcvr context) msg)
|
(:method ((rcvr context) msg)
|
||||||
(let ((hdlrs (action-handlers rcvr)))
|
(let* ((acts (actions rcvr))
|
||||||
(funcall (car hdlrs) msg))))
|
(selected (car acts))
|
||||||
|
(hdlr (car (handlers selected))))
|
||||||
|
(funcall hdlr msg))))
|
||||||
|
|
||||||
(defvar *context* nil)
|
(defvar *context* nil)
|
||||||
|
|
||||||
|
@ -48,7 +56,9 @@
|
||||||
(format t "~&~s~%" msg))
|
(format t "~&~s~%" msg))
|
||||||
|
|
||||||
(defclass printer (context)
|
(defclass printer (context)
|
||||||
((action-handlers :initform (list #'do-print))))
|
((actions :initform
|
||||||
|
(list (make-instance 'action-spec
|
||||||
|
:handlers (list #'do-print))))))
|
||||||
|
|
||||||
(defun printer (name)
|
(defun printer (name)
|
||||||
(make-instance 'printer :name name))
|
(make-instance 'printer :name name))
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
(defclass test-suite (t:test-suite)
|
(defclass test-suite (t:test-suite)
|
||||||
((receiver :reader receiver
|
((receiver :reader receiver
|
||||||
:initform (core:printer :test-rcvr))))
|
:initform (core:printer :test-rcvr))))
|
||||||
;:initform (make-instance 'core:context :name :test-rcvr))))
|
;:initform (make-instance 't:test-rcvr))))
|
||||||
|
|
||||||
(defun run ()
|
(defun run ()
|
||||||
(let ((*config* nil)
|
(let ((*config* nil)
|
||||||
|
|
Loading…
Add table
Reference in a new issue