[Openmcl-devel] How to send a message to the objc super-class ?

Gary Byers gb at clozure.com
Sun Feb 3 17:59:15 PST 2008


In the case where you want to invoke the superclass's version of
the containing method, you can use CALL-NEXT-METHOD:

(objc:defmethod (#/drawWithFrame:inView: :void)
     ((self outline-cell) frame view)
   (call-next-method frame view))

As in CL:DEFMETHOD, CALL-NEXT-METHOD is locally defined withing
OBJC:DEFMETHOD.

That provides convenient syntax for the common case; ObjC does
allow you to invoke the superclass's version of any method.
That happens a few times in the IDE sources, and it's not
pretty ... see #/updateSelection:length:affinity: on hemlock-text-storage
in ccl/cocoa-ide/cocoa-editor.lisp.  (Aside from being ugly, the
code looks up type information at runtime.)

For that case (calling the superclass's version of some other method),
something like:

(call-superclass-method #'#/setSeletedRange:affinity:stillSelecting:
   range affinity nil)

would both look a bit less ugly and be able to do a bit more at
compile-time, but it doesn't exist.  (If it existed as a local
function of macro, CALL-NEXT-METHOD could be implement in terms
of it.)

To try to be less confusing: in the common case where you want
to invoke the superclass version of the method being defined
inside an OBJC:DEFMETHOD, CALL-NEXT-METHOD is the simplest way
to do that.



On Sun, 3 Feb 2008, Didier Verna wrote:

>
>       Hello,
>
> I would like to implement the equivalent of this in Lisp:
>
> - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
> {
>  [super drawWithFrame:cellFrame inView:controlView];
> }
>
>
> However, this doesn't work:
>
> (objc:defmethod (#/drawWithFrame:inView: :void)
>    ((self outline-cell) frame view)
>  (ccl::send-super self :draw-with-frame frame :in-view view))
>
> I get the following message:
>
> 2008-02-03 18:10:39.925 iOwn[78010:10b] Lisp exception: Undefined
> function OBJC:SEND-SUPER called with arguments (#<OUTLINE-CELL
> <OutlineCell: 0x17707f20> (#x17707F20)> :DRAW-WITH-FRAME
> #<NS-OUTLINE-VIEW <NSOutlineView: 0x9b8800> (#x9B8800)> :IN-VIEW #<A
> Foreign Pointer #x4>) .
>
>
> What am I doing wrong ?
>
> Thanks !
>
>
> -- 
> Resistance is futile. You will be jazzimilated.
>
> Didier Verna, didier at lrde.epita.fr, http://www.lrde.epita.fr/~didier
>
> EPITA / LRDE, 14-16 rue Voltaire   Tel.+33 (0)1 44 08 01 85
> 94276 Le Kremlin-Bicêtre, France   Fax.+33 (0)1 53 14 59 22  didier at xemacs.org
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>


More information about the Openmcl-devel mailing list