Next: define-foreign-type, Previous: defctype, Up: Foreign Types [Contents][Index]
enum-list ::= [docstring] { keyword | (keyword value) }*
name-and-options ::= name | (name &optional (base-type :int) &key allow-undeclared-values)
The name of the new enum type.
A documentation string, ignored.
A symbol denoting a foreign type.
Whether to pass through integer values that were not explicitly declared in the enum when translating from foreign memory.
A keyword symbol.
An index value for a keyword.
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.
If a value should be translated to lisp that is not declared in the enum, an error will be signalled. You can elide this error and instead make it pass the original enum value by specifying allow-undeclared-values. This can be useful for very large enumerations of which we only care about a subset of values, or for enumerations that should allow for client or vendor extensions that we cannot know about.
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
foreign-enum-value
foreign-enum-keyword
Next: define-foreign-type, Previous: defctype, Up: Foreign Types [Contents][Index]