[Openmcl-devel] How to access Objective-C propperties
R. Matthew Emerson
rme at clozure.com
Tue Dec 28 12:40:54 PST 2010
On Dec 28, 2010, at 2:55 PM, Alexander Repenning wrote:
> I am having a problem with accessing certain (10.6 and later) objective-C properties which I try to access via objc:objc-message-send
> something like this works: (objc:objc-message-send some-event "magnification" #>CGFloat)
> but when I specify an NSPoint return type things fall apart:
> (objc:objc-message-send touch-return "normalizedPosition" #>NSPoint)
> Error: (TOUCH-RETURN :<SEL> (OBJC:@SELECTOR "normalizedPosition")) should be an even-length list of alternating foreign types and values
>> While executing: X8664::EXPAND-FF-CALL, in process Listener(6).
> I have tried to replace #>NSPoint with :id which does return something that Lisp does not like:
> Error: Invalid memory operation.
>> While executing: CCL::%SAFE-GET-PTR, in process Listener(6).
Objective-C methods that return structs have to be called differently from methods that return scalars. The details of why this is so are complicated and probably not that interesting.
Something like this (warning, typed in mail) is probably what you want.
(rlet ((pt #>NSPoint))
(objc:objc-message-send-stret pt touch-return "normalizedPosition" #>NSPoint))
Note that you pass an additional first argument, which is a pointer to some memory into which the returned struct will be stored.
More information about the Openmcl-devel