[Openmcl-devel] Cocoa bridge questions

mikel evins mikel at evins.net
Fri Apr 23 08:20:38 PDT 2004

On Apr 23, 2004, at 8:07 AM, Thom Goodsell wrote:

> Hi all,
> I'm struggling to get a firm grasp on the OpenMCL Cocoa bridge 
> starting from a moderate knowledge of Lisp and a little knowledge of 
> Cocoa (i.e., I've read a book). My current struggle is to instantiate 
> an NSPoint. The trouble is that NSPoint is a struct, not an Obj-C 
> class. Instances are usually constructed via NSMakePoint, but I can't 
> figure out how to call that, nor how to manually construct an NSPoint 
> (or even refer to one).
> I'd be most appreciative of any help. I have many more questions, but 
> I'm hoping to figure most of them out by working through some simple 
> examples.

If you want to heap-allocate the struct you want to use 
ccl::make-record. Most often, though, you'll want to stack-allocate 
such records so that they'll be cleaned up automatically on exit from 
the effective scope (but be careful not to try to store a reference to 
such a record!).

You can use make-record like so (taken from 

(make-record :<NSC>onstant<S>tring
	       :isa *NSConstantString-Class*
	       :bytes (make-cstring string)
	       :num<B>ytes (length string))

The <FOO>bar syntax is special reader syntax that enables the Lisp 
reader to read mixed-case strings for the sake of communication with 
the C world.

You can stack-allocate a record using ccl::rlet, like so (taken and 
edited from the code for my implementation of Hansa2):

(rlet ((adjusted-point :<NSP>oint
					:x (- (pref where :<NSP>oint.x)
					:y (- (pref where :<NSP>oint.y)
                      [...MORE CODE HERE...]

"[W]e were after the C++ programmers.  We managed to drag a lot of them 
about halfway to Lisp.  Aren't you happy?"

  [Guy Steele, of Sun Microsystems Labs, about designing Java]

More information about the Openmcl-devel mailing list