chickadee » foreigners » define-foreign-enum-type

(define-foreign-enum-type (type-name native-type [default-value]) (scheme->number number->scheme) enumspec ...)syntax

Defines a foreign-type that maps the elements of a C/C++ enum (or a enum-like list of constants) to and from a set of symbols. Also defines a pair of conversion procedures which can be used to do this mapping manually, along with a foreign-variable for each enumeration value.

  • type-name is the foreign type name;
  • native-type is the underlying type, e.g. int or (enum "foo");
  • default-value is the result of mapping from the native type when no such mapping exists. When supplied the form is used unquoted, otherwise the result is '();
  • scheme->number is the name of a procedure which will convert a symbol (or list of symbols) into the corresponding numeric enum value;
  • number->scheme is a procedure converting an enum into a symbol;
  • enumspec is a specification for each enum value, described in detail below.

The two procedures are defined by the macro in lexical scope for your use, and are also used in the foreign-type conversion:

(define-foreign-type type-name native-type scheme->number number->scheme)

If passed a list of symbols, scheme->number will combine their numeric values with bitwise-ior. However, number->scheme returns a single symbol and will not decompose a value into its component symbols; rather, you will probably get default-value.