You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 6: Foreign Types 38<br />
define-foreign-type<br />
Syntax<br />
define-foreign-type class-name supers slots &rest options ⇒ [Macro]<br />
class-name<br />
options ::= (:actual-type type) | (:simple-parser symbol) | regular defclass option<br />
Arguments and Values<br />
class-name<br />
supers<br />
slots<br />
Description<br />
A symbol naming the new foreign type class.<br />
A list of symbols naming the super classes.<br />
A list of slot definitions, passed to defclass.<br />
The macro define-foreign-type defines a new class class-name. It is a thin wrapper<br />
around defclass. Among other things, it ensures that class-name becomes a subclass of<br />
foreign-type, what you need to know about that is that there’s an initarg :actual-type<br />
which serves the same purpose as defctype’s base-type argument.<br />
Examples<br />
Taken from <strong>CFFI</strong>’s :boolean type definition:<br />
(define-foreign-type :boolean (&optional (base-type :int))<br />
"Boolean type. Maps to an :int by default. Only accepts integer types."<br />
(ecase base-type<br />
((:char<br />
:unsigned-char<br />
:int<br />
:unsigned-int<br />
:long<br />
:unsigned-long) base-type)))<br />
<strong>CFFI</strong>> (canonicalize-foreign-type :boolean)<br />
⇒ :INT<br />
<strong>CFFI</strong>> (canonicalize-foreign-type ’(:boolean :long))<br />
⇒ :LONG<br />
<strong>CFFI</strong>> (canonicalize-foreign-type ’(:boolean :float))<br />
;; error signalled by ECASE.<br />
See Also<br />
[defctype], page 36<br />
[define-parse-method], page 39