Next: define-foreign-type, Previous: defctype, Up: Foreign Types
enum-list ::= [docstring] { keyword | (keyword value) }* name-and-options ::= name | (name &optional (base-type :int))
The defcenum
macro is used to define foreign types that map
keyword symbols to integer values, similar to the C enum
type.
If value is omitted its value will either be 0, if it's the first entry, or it it will continue the progression from the last specified value.
Keywords will be automatically converted to values and vice-versa when
being passed as arguments to or returned from foreign functions,
respectively. The same applies to any other situations where an object
of an enum
type is expected.
Types defined with defcenum
canonicalize to base-type
which is :int
by default.
(defcenum boolean :no :yes) CFFI> (foreign-enum-value 'boolean :no) => 0
(defcenum numbers (:one 1) :two (:four 4)) CFFI> (foreign-enum-keyword 'numbers 2) => :TWO