Macro
fli
define-foreign-function name ({arg}*) &key lambda-list documentation result-type language no-check => lisp-name name ::= lisp-name | (lisp-name foreign-symbol [encoding]) | (lisp-name foreign-string [encoding]) encoding ::= :source | :object | :lisp | :dbcs arg ::= arg-name | (arg-name arg-type) | (:constant value value-type) language ::= :c | :ansi-c calling-convention ::= :stdcall | :cdecl
Either a symbol naming the defined Lisp function, or a list containing the name of the Lisp function, the corresponding foreign function name and optionally an encoding option.
A symbol naming the defined Lisp function.
A symbol naming the foreign function.
A string containing the name of the foreign function.
An option controlling how the Lisp function name is translated into the function name in the foreign object code. The encoding option can be one of the following:
:source
tells LispWorks that the string foreign-string or the symbol foreign-symbol is the name of the function in the foreign source code. This is the default value of encoding.
:object
tells LispWorks that the string foreign-string or the symbol foreign-symbol is the literal name of the function in the foreign object code.
:lisp
tells LispWorks that the symbol foreign-symbol is a Lisp symbol and must be translated and encoded.
:dbcs
adds a suffix onto the function name which will automatically change depending on whether Lisp image is started up in the Windows NT or Windows 95 operating system. The suffix is "A
" for Windows 95 and "W
" for Windows NT.
Either an argument name, a list containing an argument name and a type, or a list of the form(:constant
value value-type)
. Lisp arguments may take any name, but the types must be accurately specified and listed in the same order as in the foreign function, unless otherwise specified using lambda-list.
If only an arg-name is supplied, thendefine-foreign-function
assumes that it is of type:int
.
If arg is of the form(:constant
value value-type)
then value is always passed through to the foreign code.
The lambda list to be used for the defined Lisp function. If this is not specified, the lambda list is generated from the list of args. The lambda-list keyword allows you to define the order in which the Lisp function takes its arguments to be different from the order in which the foreign function takes them, and to use standard lambda list keywords such as&optional
. The default value of lambda-list isnil
.
A documentation string for the foreign function.
The type of the foreign function's return value.
The language in which the foreign source code is written. The default is:c
.
Ifnil
, the types of the arguments provided when the Lisp function is called are compared with the expected types and an error is raised if they do not match. Setting no-check tot
overrides this check.
If the compilation safety level is set to 0 then no-check is automatically set tot
. The default value for no-check isnil
.
Specifies the calling convention used.
:stdcall
is the calling convention used to call Win32 API functions and matches the C declarator"__stdcall"
.
:cdecl
is the default calling convention for C/C++ programs and matches the C declarator "__cdecl"
.
Specifies the module in which the foreign symbol is defined. If it is the name of a module registered usingregister-module
then that module is used to look up the symbol. If the name of the module is a string then that module is automatically registered and used to look up the symbol.
A symbol naming the defined Lisp function.
define-foreign-function
defines a Lisp function which acts as an interface to a foreign language function, for example a C function. When the Lisp function is called its arguments are converted to the appropriate foreign representation before being passed to the specified foreign function. Once the foreign function exits, any return values are converted back from the foreign format into a Lisp format. define-foreign-function
is given in "Defining an FLI function" on page 5. More detailed examples are given in Chapter 4, "Advanced Uses of the FLI". define-foreign-callable
define-foreign-variable