[Openmcl-devel] How to access Cocoa objects returned via indirect references (i.e. NSError)

Phil pbpublist at comcast.net
Mon Jul 24 21:53:11 PDT 2006


On Jul 24, 2006, at 11:35 PM, Gary Byers wrote:

>
> I'm not sure that I understand the question,

You caught the essence of my question despite my poor wording.

>
> Note that if something's returned by reference, you'd generally
> do something like:
>
>  (let* ((ns-error-ptr :id))
>    (send some-message ... ns-error-ptr ...)
>    (let* ((the-ns-error (pref ns-error-ptr :id)))
>      ;; At this point, THE-NS-ERROR should be an NSError (or possibly
>      ;; a NULL pointer if there was no error ...
>      ...)))
>
> (That's no different from how other things are returned by reference.)
>

That is what I was struggling with and mostly solved my problem.  The  
first let with (ns-error-ptr :id) resulted in an error (The value :ID  
is not of the expected type MACPTR) in the send some-message.  Here's  
the relevant snippet:

(ccl::with-autorelease-pool
   (let* ((error-ptr (ccl::make-objc-instance 'ns-error)) ; :id  
results in error
             (the-xml (ccl::make-objc-instance 'ns-xml-document
                                                                         
  :init-with-contents-of-url (ccl::send (ccl::@class ns-url)
                                                                         
                                                                :url- 
with-string #@"http://blah")
                                                                         
  :options (logior #$NSXMLNodePreserveWhitespace
                                                                         
                              #$NSXMLNodePreserveCDATA)
                                                                         
  :error error-ptr)))
     (if error-ptr
       (let ((the-error (ccl::pref error-ptr :id)))
         (format t "An error was encountered: ~a~%" the-error)))
     the-xml))




More information about the Openmcl-devel mailing list