-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathevent.lisp
48 lines (42 loc) · 1.76 KB
/
event.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(in-package #:org.shirakumo.maiden)
(defclass event-class (deeds:event-class)
((effective-advice :initform () :accessor advice)
(direct-advice :initarg :advice :accessor direct-advice))
(:default-initargs
:direct-advice ()))
(defmethod c2mop:finalize-inheritance :after ((class event-class))
(let ((advice ()))
;; Calculate inherited advice
(dolist (super (c2mop:class-direct-superclasses class))
(when (typep super 'event-class)
(unless (c2mop:class-finalized-p super)
(c2mop:finalize-inheritance super))
(setf advice (union advice (advice super)))))
;; Remove blocked advice
(when (slot-boundp class 'direct-advice)
(dolist (direct-advice (direct-advice class))
(cond ((and (listp direct-advice) (eql (first direct-advice) 'not))
(setf advice (remove (second direct-advice) advice)))
((listp direct-advice)
(setf advice (union advice direct-advice :test #'equalp)))
(T
(pushnew direct-advice advice :test #'equalp)))))
;; Set effective advice.
(setf (advice class) advice)))
(defclass event (deeds:event)
()
(:metaclass event-class))
(defmethod advice ((event event))
(advice (class-of event)))
(defmethod core ((event event))
(event-loop event))
(defmacro define-event (name direct-superclasses direct-slots &rest options)
(when (loop for super in direct-superclasses
never (c2mop:subclassp (find-class super) (find-class 'event)))
(push 'event direct-superclasses))
(pushnew `(:metaclass event-class) options
:test #'(lambda (a b) (eql (car a) (car b))))
`(eval-when (:compile-toplevel :load-toplevel :execute)
(defclass ,name ,direct-superclasses
,direct-slots
,@options)))