Re: Making a c-style array

"R. Matthew Emerson" <[email protected]>
Newsgroups gmane.lisp.openmcl.devel
Message-ID <[email protected]>

> On Feb 22, 2023, at 3:20 AM, Arthur Cater <[email protected]> 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)))))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.