Hi,
I've been fighting with MOP today, and there's obviously something I'm
missing. What I want to do is a simple metaclass for serialisable packets
that would ensure proper type definitions so that packets can be declared
and guaranteed to have a defined specialisatiuon.
I have the following code:
(in-package :pp)
(defclass serialisable (standard-class)
())
(defmethod make-instance :after ((class serialisable) &rest args)
(format t "Packet: ~A" args))
(defmethod sb-mop:validate-superclass ((class serialisable)
(superclass standard-class))
t)
(defmacro defpacket (&body body)
`(defclass ,@body
(:metaclass serialisable)))
PP> (defpacket fasd ()
((foo :initarg :foo)))
===>
#<POKER-PACKET::SERIALISABLE FASD> ;; Expected Packet: ...
(defmethod make-instance :after ((class standard-class) &rest args)
(format t "Packet: ~A" args))
PP> (pp::defpacket fasd ()
((foo :initarg :foo)))
===>
Packet: (CLASS #<SERIALISABLE FASD> NAME FOO READERS NIL WRITERS NIL
INITARGS (FOO))
#<POKER-PACKET::SERIALISABLE FASD>
I don't understand the above. If I define a class X with metaclass Y,
then there should happen a call to (make-instance 'Y). Which is exactly
what my first defmethod attempts to do, except it doesn't work. Even more
baffling is how it does get invoked when I specialise on STANDARD-CLASS,
and clearly shows there *is* SERIALISABLE involved. I'd be very grateful
for any explanation of this mystery, I'm sure it's something simple and
silly, but I'm unable to track it down.
Cheers,
Maciej