[Openmcl-devel] Implementing cocoa methods that return NSRect

Gary Byers gb at clozure.com
Tue Feb 22 22:19:49 UTC 2005



On Sun, 20 Feb 2005, Anders Conradi wrote:

> Hi,
>
> How do you implement cocoa methods that return structures like NSRect?
>
> // Anders
>

I've been out of town for a few days and don't know if this got answered.

A C function (or lisp callback) that "returns a structure" receives an
extra first parameter that's a pointer to an instance of that structure
class, allocated by the caller.  The structure-returning function just
fills in the structure's slots and doesn't (conventionally) return an
interesting value.

The syntax for this in DEFINE-OBJC-METHOD is a little weird.  The only
example that I could find looks like:

(define-objc-method (((:struct :<NSR>ange r)
                      :selection-range-for-proposed-range (:<NSR>ange proposed)
                      :granularity (:<NSS>election<G>ranularity g))
                     hemlock-textstorage-text-view)
 ...)

The "return type spec" here is a list that starts with the keyword :STRUCT
(I suppose that that's a little redundant) and explicitly names the
structure pointer argument (R, in this case) so that code in the body
can do:

      (setf (pref r :<NSR>ange.location) ...)




More information about the Openmcl-devel mailing list