Lisp HUG Maillist Archive

Obj-C subclassing behavior

I have a possible bug, but wondering if this was normal (or even desired) behavior in the :objc package... I've created a framework using Cocoa and created a simple class like so:

@interface foo : NSObject { }
- (void)bar: (id)anObject;
- (void)setup;
@end

And it is implemented.

In LW, I then want to sublcass this and send -bar: messages to it. So, I go for it:

(define-objc-class my-foo ()
  ()
  (:objc-class-name "my-foo")
  (:objc-superclass-name "foo"))

Now I'll override -setup (that the framework will call automagically when I use the object):

(define-objc-method ("setup" :void)
    ((self my-foo))
  (invoke self "bar:" nil))

The above call to -bar: will now either crash with an unrecoverable error that's something like "<object my-foo> is an invalid parameter to function null-pointer-p". Please note that the two additional pieces of info:

(let ((o (alloc-init-object "my-foo")))
  (can-invoke-p o "bar:"))

--> T

Also, if I change the call in the setup method to:

(invoke (current-super) "bar:" nil)

Everything works as expected. Any ideas?

Jeff M.

Re: Obj-C subclassing behavior

Nevermind. I just figured out that I needed to use
(objc-object-pointer self). I didn't realize that self would be a lisp
object and not the objective-c object.

Duh. ;-)

Jeff M.


Re: Obj-C subclassing behavior


On Jul 28, 2008, at 5:26 PM, Jeff Massung wrote:

> Nevermind. I just figured out that I needed to use
> (objc-object-pointer self). I didn't realize that self would be a lisp
> object and not the objective-c object.

I've run into this myself - kind of counterintuitive for "self" to not  
be an objective-c object.

regards,

Ralph







Raffael Cavallaro, Ph.D.
raffaelcavallaro@mac.com


Updated at: 2020-12-10 08:42 UTC