Package: cffi

Macro define-foreign-type

Lambda List

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

Syntax

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

Arguments

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.

Details

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.

Examples

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
      ((:char
        :unsigned-char
        :int
        :unsigned-int
        :long
        :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