Common lisp, CFFI and instantiation with c structs

I was on google about, oh, 3 hours looking for a solution to this "problem". I am trying to figure out how to instantiate a C structure in lisp using CFFI. I have a structure in c:

struct cpVect{cpFloat x,y;}

Simple? I have automatically created CFFI bindings (swig, I think) to this structure:

(cffi:defcstruct #.(chipmunk-lispify "cpVect" 'classname)
    (#.(chipmunk-lispify "x" 'slotname) :double)
    (#.(chipmunk-lispify "y" 'slotname) :double))

This creates a "VECT" structure with slots: X and: Y that confirm the names of foreign slots (note that I did not generate bindings or program the C library (chipmunk physics), but the actual functions are called from lisp just fine).

I searched around the world, and maybe I saw it 100 times and hush it up, but I can't figure out how to instantiate cpVect in lisp for use in other functions.

Pay attention to the function:

cpShape *cpPolyShapeNew(cpBody *body, int numVerts, cpVect *verts, cpVect offset)

cpVect, cpVects, : ?

http://common-lisp.net/project/cffi/manual/html_node/defcstruct.html , "Error: Unbound variable: PTR" ( Clozure CL), , , .

lisp, , , , . !

+3
2

Lisp . fsbv, libffi . , , .

+2

, , Ruby FFI : https://github.com/shawn42/chipmunk-ffi/blob/master/lib/chipmunk-ffi/vec2.rb

Chipmunk , inline-, FFI . cpv. cpv - , cpVect. github w/me (shawn42).

+1

Source: https://habr.com/ru/post/1782892/


All Articles