This is the way I thought you did it but I'm running this and it's not working:
(with-foreign-object (float :float) (setf float 6) (type-of float))
>(INTEGER 0 4611686018427387903)
The output says it is an integer
I tried this:
(with-foreign-object (float :float) (setf (mem-ref float :float) 4) (type-of (mem-ref float :float)))
And get this error:
Value of #1=#:VALUE4 in (SB-KERNEL:%SET-SAP-REF-SINGLE FLOAT 0 #1#) is 4, not a SINGLE-FLOAT. [Condition of type SIMPLE-TYPE-ERROR]
If someone could help me cast in CFFI I would appreciate it. the word "cast" isn't even in the CFFI documentation. I just would like to be able to cast anything, from functions to variable into other types. Any maybe if someone skilled in CFFI can tell me if it so good that it can do any thing you can in C. I would appreciate that too.
On Sun, 2014-03-30 at 06:59 -0700, Joeish W wrote:
This is the way I thought you did it but I'm running this and it's not working:
(with-foreign-object (float :float) (setf float 6) (type-of float)) >(INTEGER 0 4611686018427387903)
The output says it is an integer
I tried this:
(with-foreign-object (float :float) (setf (mem-ref float :float) 4) (type-of (mem-ref float :float)))
(with-foreign-object (float :float) (setf (mem-ref float :float) (coerce 4 'single-float)) (mem-ref float :float))
or use the syntax 4.0s0 for a literal single-float(4.0d0 is a literal double in comparison).
Thanks for getting back to me., I really appreciate it
Using coerce though I'm already casting it to a float on the lisp side...I was wondering if I can cast a 4 to a float with CFFI and have the output be a 4.0f0 like it works in C...without doing anything on the Lisp side
On Sunday, March 30, 2014 7:12 AM, Stelian Ionescu sionescu@cddr.org wrote:
On Sun, 2014-03-30 at 06:59 -0700, Joeish W wrote:
This is the way I thought you did it but I'm running this and it's not working:
(with-foreign-object (float :float) (setf float 6) (type-of float))
>(INTEGER 0 4611686018427387903)
The output says it is an integer
I tried this:
(with-foreign-object (float :float) (setf (mem-ref float :float) 4) (type-of (mem-ref float :float)))
(with-foreign-object (float :float) (setf (mem-ref float :float) (coerce 4 'single-float))
(mem-ref float :float))
or use the syntax 4.0s0 for a literal single-float(4.0d0 is a literal double in comparison).
-- Stelian Ionescu a.k.a. fe[nl]ix Quidquid latine dictum sit, altum videtur.
On Sun, 2014-03-30 at 07:18 -0700, Joeish W wrote:
Thanks for getting back to me., I really appreciate it
Using coerce though I'm already casting it to a float on the lisp side...I was wondering if I can cast a 4 to a float with CFFI and have the output be a 4.0f0 like it works in C...without doing anything on the Lisp side
CFFI doesn't do automatic coercions, but you can do it with a custom type:
(define-foreign-type float+int () () (:actual-type :float) (:simple-parser float+int))
(defmethod expand-to-foreign (value (type float+int)) `(coerce ,value 'float))
(with-foreign-object (val :float) (setf (mem-ref val 'float+int) 4) (mem-ref val :float))