Hi,
I have a problem getting automatic type translation to work. In my cl-cairo2 package (http://www.cliki.net/cl-cairo2), some cairo functions expect booleans, but I want them to work with integers etc. I set up a translate-to-foreign method as described in the manual, and was using it, but recently it stopped working, in the sense that translate-to-foreign still works when called manually, but functions don't seem to call it (they did before, I changed nothing), and when trying to check with convert-to-foreign, that does not work either.
I reduced my problem to a small, clean example:
(require :cffi)
(cffi:defctype my-double :double)
(defmethod cffi:translate-to-foreign (value (type (eql 'my-double))) (coerce value 'double-float))
(cffi:translate-to-foreign 10 'my-double) ; => 10d0
(cffi:convert-to-foreign 10 'my-double) ; => 10, should be 10d0!
What am I doing wrong?
Thanks,
Tamas
PS: cl-cffi 20080217-1, sbcl 1:1.0.14.0-1.
On Mon, Apr 21, 2008 at 12:42 AM, Tamas K Papp tpapp@princeton.edu wrote:
(cffi:defctype my-double :double)
(defmethod cffi:translate-to-foreign (value (type (eql 'my-double))) (coerce value 'double-float))
That should be:
* (define-foreign-type my-double-type () () (:actual-type :double) (:simple-parser my-double))
MY-DOUBLE-TYPE * (defmethod translate-to-foreign (value (type my-double-type)) (coerce value 'double-float))
#<STANDARD-METHOD TRANSLATE-TO-FOREIGN (T MY-DOUBLE-TYPE) {1003370511}> * (convert-to-foreign 10 'my-double)
10.0d0
On Mon, Apr 21, 2008 at 01:54:05PM +0100, Luís Oliveira wrote:
On Mon, Apr 21, 2008 at 12:42 AM, Tamas K Papp tpapp@princeton.edu wrote:
(cffi:defctype my-double :double)
(defmethod cffi:translate-to-foreign (value (type (eql 'my-double))) (coerce value 'double-float))
That should be:
- (define-foreign-type my-double-type () () (:actual-type :double) (:simple-parser my-double))
MY-DOUBLE-TYPE
- (defmethod translate-to-foreign (value (type my-double-type)) (coerce value 'double-float))
#<STANDARD-METHOD TRANSLATE-TO-FOREIGN (T MY-DOUBLE-TYPE) {1003370511}>
- (convert-to-foreign 10 'my-double)
10.0d0
Hi Luis,
Thanks for the fast response, it fixed my problem.
Maybe mentioning define-foreign-type in section 5.4 (Foreign Type Translators) of the manual would help. Your example works perfectly, but the define-foreign-type documentation mentions neither :actual-type and :simple-parser.
Tamas
On Mon, Apr 21, 2008 at 2:55 PM, Tamas K Papp tpapp@princeton.edu wrote:
Maybe mentioning define-foreign-type in section 5.4 (Foreign Type Translators) of the manual would help. Your example works perfectly, but the define-foreign-type documentation mentions neither :actual-type and :simple-parser.
Well, it does. But the on-line manual refers to version 0.9.2. This will be fixed soon, I hope.