basic set-up of actions in context with action-spec

This commit is contained in:
Helmut Merz 2024-06-12 10:13:19 +02:00
parent 367f5ae589
commit 645f008362
2 changed files with 15 additions and 5 deletions

View file

@ -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))

View file

@ -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)