The specification files are read by the normal Lisp reader, so they have syntax very similar to normal Lisp code. In particular, semicolon-comments and reader-macros will work as expected.
There are several forms recognized by CFFI-Grovel:
Processes a list of forms. Useful for conditionalizing several forms. For example:
#+freebsd
(progn
(constant (ev-enable "EV_ENABLE"))
(constant (ev-disable "EV_DISABLE")))
Include the specified files (specified as strings) in the generated C source code.
Define a CFFI foreign type for the string in size-designator, e.g.
(ctype :pid "pid_t")
.
Search for the constant named by the first c-name string found to be known to the C preprocessor and define it as lisp-name.
The type keyword argument specifies how to grovel the constant: either
integer
(the default) ordouble-float
. If optional is true, no error will be raised if all the c-names are unknown. If lisp-name is a keyword, the actual constant will be a symbol of the same name interned in the current package.
Defines an additional C preprocessor symbol, which is useful for altering the behavior of included system headers.
Adds cc-flags to the command line arguments used for the C compiler invocation.
Define a CFFI foreign struct with the slot data specfied. Slots are of the form
(lisp-name c-name &key type count (signed t))
.
Identical to
cstruct
, but defines a CFFI foreign union.
Defines a CFFI foreign struct, as with
cstruct
and defines a CLOS class to be used with it. This is useful for mapping foreign structures to application-layer code that shouldn't need to worry about memory allocation issues.
Defines a foreign variable of the specified type, even if that variable is potentially a C preprocessor pseudo-variable. e.g.
(cvar ("errno" errno) errno-values)
, assuming that errno-values is an enum or equivalent to type:int
.The namespec is similar to the one used in defcvar.
Defines a true C enum, with elements specified as
((lisp-name &rest c-names) &key optional documentation)
. name-and-opts can be either a symbol as name, or a list(name &key base-type define-constants)
. If define-constants is non-null, a Lisp constant will be defined for each enum member.
Defines an enumeration of pre-processor constants, with elements specified as
((lisp-name &rest c-names) &key optional documentation)
. name-and-opts can be either a symbol as name, or a list(name &key base-type define-constants)
. If define-constants is non-null, a Lisp constant will be defined for each enum member.This example defines
:af-inet
to represent the value held byAF_INET
orPF_INET
, whichever the pre-processor finds first. Similarly for:af-packet
, but no error will be signalled if the platform supports neitherAF_PACKET
norPF_PACKET
.
(constantenum address-family
((:af-inet "AF_INET" "PF_INET")
:documentation "IPv4 Protocol family")
((:af-local "AF_UNIX" "AF_LOCAL" "PF_UNIX" "PF_LOCAL")
:documentation "File domain sockets")
((:af-inet6 "AF_INET6" "PF_INET6")
:documentation "IPv6 Protocol family")
((:af-packet "AF_PACKET" "PF_PACKET")
:documentation "Raw packet access"
:optional t))