Lisp HUG Maillist Archive

Accessing NSError value

I have the following code as part of an application using the QTKit framework.
Earlier this week Martin Simmons had simple solution to access C variables. 
I am wondering if there is also an easy solution to access NSError instances. 

Thanks for any help.

Bruno

Here is the Objective-C code that I am trying to replicate with LW. 
NSError *error;

QTCaptureDevice *videoDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo];

[videoDevice open:&error];

Here is the lisp code

(defvar nserror (objc:alloc-init-object  "NSError"))

(defmacro define-string-constant (lisp-name objc-name)
 `(dspec:def (define-string-constant ,lisp-name)
    (fli:define-foreign-variable (,lisp-name ,objc-name)
      :type objc:objc-object-pointer :accessor :read-only)))

(define-string-constant qt-media-type-video "QTMediaTypeVideo")

(defmethod default-video-device ()
  (objc:invoke "QTCaptureDevice" "defaultInputDeviceWithMediaType:"  (qt-media-type-video)))

(objc:invoke (default-video-device) "open:" nserror)


Re: Accessing NSError value

Oh. well...
It looks like the following works. 

(defparameter nserror (fli:make-pointer 
                                              :address (fli:pointer-address (alloc-init "NSError")) 
                                              :type 'objc:objc-object-pointer))

Bruno

On 13-Feb-08, at 3:52 PM, Bruno Emond wrote:

I have the following code as part of an application using the QTKit framework.
Earlier this week Martin Simmons had simple solution to access C variables. 
I am wondering if there is also an easy solution to access NSError instances. 

Thanks for any help.

Bruno

Here is the Objective-C code that I am trying to replicate with LW. 
NSError *error;
QTCaptureDevice *videoDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo];
[videoDevice open:&error];

Here is the lisp code

(defvar nserror (objc:alloc-init-object  "NSError"))

(defmacro define-string-constant (lisp-name objc-name)
 `(dspec:def (define-string-constant ,lisp-name)
    (fli:define-foreign-variable (,lisp-name ,objc-name)
      :type objc:objc-object-pointer :accessor :read-only)))

(define-string-constant qt-media-type-video "QTMediaTypeVideo")

(defmethod default-video-device ()
  (objc:invoke "QTCaptureDevice" "defaultInputDeviceWithMediaType:"  (qt-media-type-video)))

(objc:invoke (default-video-device) "open:" nserror)



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