Package: cffi

Macro define-foreign-type

Lambda List

define-foreign-type (name supers slots &rest options)


options ::= (:actual-type type) | (:simple-parser symbol) | regular defclass option


class-name -- A symbol naming the new foreign type class.
supers -- A list of symbols naming the super classes.
slots -- A list of slot definitions, passed to defclass.


The macro define-foreign-type defines a new class class-name. It is a thin wrapper around defclass. Among other things, it ensures that class-name becomes a subclass of foreign-type, what you need to know about that is that there's an initarg :actual-type which serves the same purpose as defctype's base-type argument.


Taken from CFFI's :boolean type definition:
  (define-foreign-type :boolean (&optional (base-type :int))
    "Boolean type. Maps to an :int by default. Only accepts integer types."
    (ecase base-type
        :unsigned-long) base-type)))

CFFI> (canonicalize-foreign-type :boolean) => :INT CFFI> (canonicalize-foreign-type '(:boolean :long)) => :LONG CFFI> (canonicalize-foreign-type '(:boolean :float)) ;; error--> signalled by ECASE.

See also