All Manuals > LispWorks Objective-C and Cocoa Interface User Guide and Reference Manual > 1 Introduction to the Objective-C Interface > 1.3 Invoking Objective-C methods

NextPrevUpTopContentsIndex

1.3.5 Invoking a method that returns a structure

As mentioned in Special argument and result conversion, when invoke is used with a method whose return type is one of the structure types listed in Special argument and result conversion for invoke, such as NSRect , a vector or cons containing the fields of the structure is returned. For other structure types defined with define-objc-struct, the function invoke-into must be used to call the method. This takes the same arguments as invoke, except that there is an extra initial argument, result , which should be a pointer to a foreign structure of the appropriate type for the method. When the method returns, the value is copied into this structure.

For example, a call in Objective-C such as:

{
  NSRect rect = [box frame];
  ...
}

could be written using invoke-into as:

(fli:with-dynamic-foreign-objects ((rect cocoa:ns-rect))
  (objc:invoke-into rect box "frame")
  ...)

In addition, for the structure return types mentioned in Special argument and result conversion for invoke, an appropriately sized vector or cons can be passed as result and this is filled with the field values.

For example, the above call could also be written using invoke-into as:

(let ((rect (make-array 4)))
  (objc:invoke-into rect box "frame")
  ...)

LispWorks Objective-C and Cocoa Interface User Guide and Reference Manual - 15 Dec 2011

NextPrevUpTopContentsIndex