Next: , Previous: , Up: Foreign Types   [Contents][Index]


define-foreign-type

define-foreign-type

Syntax

Macro: define-foreign-type class-name supers slots &rest options ⇒ class-name

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

Arguments and Values

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.

Description

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

defctype
define-parse-method