Lisp HUG Maillist Archive

Why is objc-object-pointer nil?

Hi,

I define an Objective C class, make an instance, but the objective c pointer is nil. Do I need to do anything more to get an object pointer from a lisp object?

CL-USER> (objc:define-objc-class hello ()
                                  ((name :initarg :name :accessor name :initform nil))
                                  (:objc-class-name "Hello"))
 HELLO
CL-USER> (setf hello-obj (make-hello "Deepak"))
 #<HELLO 200C7AFB>
CL-USER> (typep hello-obj 'objc:standard-objc-object)
 T
CL-USER> (objc:objc-object-pointer hello-obj)
NIL

This page http://www.lispworks.com/documentation/lw61/OBJC/html/objc-23.htm#pgfId-890700 specifies that "an associated foreign Objective-C object of the class MyObject is allocated by calling the class's "alloc" method and initialized by calling the instance's "init" method." 

Isn't this objective c object created automatically?

Thanks,
Deepak
--
http://deepaksurti.com
To see a miracle, be the miracle.

Re: Why is objc-object-pointer nil?

Hi Deepak,

> On 28 nov. 2013, at 15:34, Deepak Surti <dmsurti@gmail.com> wrote:
> 
> I define an Objective C class, make an instance, but the objective c pointer is nil. Do I need to do anything more to get an object pointer from a lisp object?

I think you need to specify the superclass, NSObject.

Best,
Camille


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: Why is objc-object-pointer nil?

Hi Camille,

Thanks for the suggestion. But that did not work. 

When I look at the reference for standard-objc-object (http://www.lispworks.com/documentation/lw61/OBJC/html/objc-69.htm#pgfId-1138236), it states these:
1. The class from which all classes that implement an Objective-C class should inherit.
2. Subclasses are typically defined using define-objc-class, which allows the Objective-C class name to be specified. Instances of such a subclass have an associated Objective-C foreign object whose pointer can be retrieved using the objc-object-pointer accessor.
3. There are two ways that subclasses of standard-objc-object can be made:
  • Via make-instance . In this case, the Objective-C object is allocated automatically by calling the Objective-C class's "alloc" method.
As such this confuses me even further as to why the Objective-C object is not allocated automatically! 

I have tried both standard-objc-object as well as NSObject as superclass and none of it works for objc-object-pointer.

Regards,
Deepak


On Thu, Nov 28, 2013 at 8:23 PM, Camille Troillard <camille@osculator.net> wrote:
Hi Deepak,

> On 28 nov. 2013, at 15:34, Deepak Surti <dmsurti@gmail.com> wrote:
>
> I define an Objective C class, make an instance, but the objective c pointer is nil. Do I need to do anything more to get an object pointer from a lisp object?

I think you need to specify the superclass, NSObject.

Best,
Camille




--
http://deepaksurti.com
To see a miracle, be the miracle.

Re: Why is objc-object-pointer nil?

Unable to parse email body. Email id is 12661

Re: Why is objc-object-pointer nil?

Hi Martin,

Thanks. With objc:ensure-objc-initialized, it now works perfectly!

Regards,
Deepak


On Thu, Nov 28, 2013 at 9:20 PM, Martin Simmons <martin@lispworks.com> wrote:

>>>>> On Thu, 28 Nov 2013 20:04:00 +0530, Deepak Surti said:
>
> Hi,
>
> I define an Objective C class, make an instance, but the objective c
> pointer is nil. Do I need to do anything more to get an object pointer from
> a lisp object?
>
> CL-USER> (objc:define-objc-class hello ()
>                                   ((name :initarg :name :accessor name
> :initform nil))
>                                   (:objc-class-name "Hello"))
>  HELLO
> CL-USER> (setf hello-obj (make-hello "Deepak"))
>  #<HELLO 200C7AFB>
> CL-USER> (typep hello-obj 'objc:standard-objc-object)
>  T
> CL-USER> (objc:objc-object-pointer hello-obj)
> *NIL*
>
> This page
> http://www.lispworks.com/documentation/lw61/OBJC/html/objc-23.htm#pgfId-890700specifies
> that "
> an associated foreign Objective-C object of the class MyObject is allocated
> by calling the class's "alloc" method and initialized by calling the
> instance's "init" method."
>
> *Isn't this objective c object created automatically?*

This can happen if you don't call objc:ensure-objc-initialized (see
http://www.lispworks.com/documentation/lw61/OBJC/html/objc-5.htm).  We will
look at giving a proper error in this case.

--
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html




--
http://deepaksurti.com
To see a miracle, be the miracle.
Updated at: 2020-12-10 08:34 UTC