Next: , Previous: The alien-funcall Primitive, Up: Foreign Function Calls


7.7.2 The define-alien-routine Macro

— Macro: sb-alien:define-alien-routine name result-type &rest arg-specifiers

The define-alien-routine macro is a convenience for automatically generating Lisp interfaces to simple foreign functions. The primary feature is the parameter style specification, which translates the C pass-by-reference idiom into additional return values.

name is usually a string external symbol, but may also be a symbol Lisp name or a list of the foreign name and the Lisp name. If only one name is specified, the other is automatically derived as for extern-alien. result-type is the alien type of the return value.

Each element of the arg-specifiers list specifies an argument to the foreign function, and is of the form

          (aname atype &optional style)
     

aname is the symbol name of the argument to the constructed function (for documentation). atype is the alien type of corresponding foreign argument. The semantics of the actual call are the same as for alien-funcall. style specifies how this argument should be handled at call and return time, and should be one of the following:

Note: Any efficiency-critical foreign interface function should be inline expanded, which can be done by preceding the define-alien-routine call with:
               (declaim (inline lisp-name))
          

In addition to avoiding the Lisp call overhead, this allows pointers, word-integers and floats to be passed using non-descriptor representations, avoiding consing.)