Page 1 of 1

CFFI - Is the correct name for these, METAOBJECTS

Posted: Sun May 11, 2014 3:26 pm
by joeish80829
I have my CFFI types defined as below so if I call a function that uses these types as a return it outputs a cool looking symbol as a return value e.g.

I have this function:

Code: Select all

(defcfun ("create_std_vectorf" %vec-float) vector-float)
when I call it like this:

Code: Select all

CV> (VEC-FLOAT)
#<STD-VECTOR-FLOAT {100352FEA3}>  <---It outputs this....what is this called, a METAOBJECT???

;; VECTOR-FLOAT

(define-foreign-type vector-float ()
((garbage-collect :reader garbage-collect :initform nil :initarg
:garbage-collect))
(:actual-type :pointer)
(:simple-parser vector-float))


(defclass std-vector-float ()
((c-pointer :reader c-pointer :initarg :c-pointer)))


(defmethod translate-to-foreign ((lisp-value std-vector-float) (c-type vector-float))
(values (c-pointer lisp-value) lisp-value))


(defmethod translate-from-foreign (c-pointer (c-type vector-float))
(let ((vector-float (make-instance 'std-vector-float :c-pointer c-pointer)))
(when (garbage-collect c-type)
(tg:finalize vector-float (lambda () (del-vec-flt c-pointer))))
vector-float))

Re: CFFI - Is the correct name for these, METAOBJECTS

Posted: Sun May 11, 2014 5:15 pm
by Goheeca
It's a normal CLOS object and its printed representation isn't readable. (it's denoted by the #< reader macro.)

Re: CFFI - Is the correct name for these, METAOBJECTS

Posted: Sun May 11, 2014 5:24 pm
by joeish80829
So thats why I can do this, because of the reader macro(point-x retrieves the x coordinate of point)

CV> (point 1 2)
#<CV-POINT {1007540673}>
CV> (defparameter a #<CV-POINT {1007540673}>)
A
CV> (point-x a)
1

So in my documentation, what would be the most professional way to refer to it, as a CLOS object, or just "object"?

Re: CFFI - Is the correct name for these, METAOBJECTS

Posted: Sun May 11, 2014 5:42 pm
by Goheeca
It's precisely what you can't do. And if your record of REPL is reality then CFFI or something else had to changed the behaviour of the #<.

If the documentation were structured I'd mention that objects are from CLOS only in a superficial part of it.

Re: CFFI - Is the correct name for these, METAOBJECTS

Posted: Sun May 11, 2014 5:51 pm
by joeish80829
Wow..I did that no problem, that is the direct REPL output...my CFFI is stock as is everything else...Emacs is about as tricked out as can be but SBCL is stock. I import SWANK again as a hack though. I do all my coding in my main package, I guess it could be some setting in there.

Re: CFFI - Is the correct name for these, METAOBJECTS

Posted: Sun May 11, 2014 10:01 pm
by joeish80829
Thanks again for all your help today Goheeca, I learned a lot