[Openmcl-devel] Making a c-style array

R. Matthew Emerson rme at acm.org
Wed Feb 22 10:53:33 PST 2023



> On Feb 22, 2023, at 3:20 AM, Arthur Cater <arthur.cater at ucd.ie> wrote:
> 
> To use #/elementAtIndex:associatedPoints: the Apple docs say
> - (NSBezierPathElement)elementAtIndex:(NSInteger)index 
> associatedPoints:(NSPointArray)points;
> 
> ParametersindexThe index of the desired path element.pointsOn input, a C-style array containing up to three NSPoint data types, or NULL if you do not want the points. On output, the data points associated with the specified path element. 
> 
> 
> So I now understand that ccl’s make-heap-ivector lets me create an array, but I don’t understand how to pass it an appropriate element-type for accommodating NSPoints. Can anyone help please?
> Arthur
> 


I would suggest something like the following.  A heap ivector is handy when you need heap-allocated memory, but rlet/rletz, which allocates on the stack, is often what you want when calling foreign code. Note that the stack-allocated data becomes invalid when the rlet scope is exited, so be sure to copy out any data you need.

(defun foo ()
  (rletz ((points (:array #>NSPoint 3)))
    (let* ((path (#/bezierPathWithRect: ns:ns-bezier-path (ns:make-ns-rect 1 2 30 10)))
           (element (#/elementAtIndex:associatedPoints: path 1 points))
           (point (paref points (:array #>NSPoint) 0)))
      (format t "~s" path)
      (format t "~&element ~s, " element)
      (format t "(~f, ~f)" (pref point :<NSP>oint.x) (pref point :<NSP>oint.y)))))





More information about the Openmcl-devel mailing list