CFFI - Is the correct name for these, METAOBJECTS

Discussion of Common Lisp
Post Reply
joeish80829
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

CFFI - Is the correct name for these, METAOBJECTS

Post by joeish80829 » Sun May 11, 2014 3:26 pm

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))

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

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

Post by Goheeca » Sun May 11, 2014 5:15 pm

It's a normal CLOS object and its printed representation isn't readable. (it's denoted by the #< reader macro.)
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

joeish80829
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

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

Post by joeish80829 » Sun May 11, 2014 5:24 pm

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"?

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

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

Post by Goheeca » Sun May 11, 2014 5:42 pm

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.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

joeish80829
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

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

Post by joeish80829 » Sun May 11, 2014 5:51 pm

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.

joeish80829
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

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

Post by joeish80829 » Sun May 11, 2014 10:01 pm

Thanks again for all your help today Goheeca, I learned a lot

Post Reply