## Functions & Libraries

## `def-function`

Declares a function.

### Macro

         def-function name args &key module returning

`name`

  A string or list specificying the function name. If it is a string, that names the foreign function. A Lisp name is created by translating #\_ to #\- and by converting to upper-case in case-insensitive Lisp implementations. If it is a list, the first item is a string specifying the foreign function name and the second it is a symbol stating the Lisp name.

`args`

  A list of argument declarations. If &nil;, indicates that the function does not take any arguments.

`module`

  A string specifying which module (or library) that the foreign function resides. (Required by Lispworks)

returning

  A declaration specifying the result type of the foreign function. If `:void` indicates module does not return any value.

### Description

Declares a foreign function.

### Examples

    (def-function "gethostname"
        ((name (* :unsigned-char))
         (len :int))
       :returning :int)

### Side Effects

None.

### Affected by

None.

### Exceptional Situations

None.

## `load-foreign-library`

Loads a foreign library.

### Function

         load-foreign-library filename &key module supporting-libraries force-load => success

`filename`

  A string or pathname specifying the library location in the filesystem. At least one implementation (&LW;) can not accept a logical pathname. If this parameter denotes a pathname without a directory component then most of the supported Lisp implementations will be able to find the library themselves if it is located in one of the standard locations as defined by the underlying operating system.

`module`

  A string designating the name of the module to apply to functions in this library. (Required for Lispworks)

`supporting-libraries`

  A list of strings naming the libraries required to link the foreign library. (Required by CMUCL)

`force-load`

  Forces the loading of the library if it has been previously loaded.

success

  A boolean flag, &t; if the library was able to be loaded successfully or if the library has been previously loaded, otherwise &nil;.

### Description

Loads a foreign library. Applies a module name to functions within the library. Ensures that a library is only loaded once during a session. A library can be reloaded by using the :force-load key.

### Examples

    (load-foreign-library #p"/usr/lib/libmysqlclient.so"
                          :module "mysql"
                         :supporting-libraries '("c"))
    => T

### Side Effects

Loads the foreign code into the Lisp system.

### Affected by

Ability to load the file.

### Exceptional Situations

None.

## `find-foreign-library`

Finds a foreign library file.

### Function

         find-foreign-library names directories & drive-letters types => path

`names`

  A string or list of strings containing the base name of the library file.

`directories`

  A string or list of strings containing the directory the library file.

`drive-letters`

  A string or list of strings containing the drive letters for the library file.

`types`

  A string or list of strings containing the file type of the library file. Default is &nil;. If &nil;, will use a default type based on the currently running implementation.

path

  A path containing the path found, or &nil; if the library file was not found.

### Description

Finds a foreign library by searching through a number of possible locations. Returns the path of the first found file.

### Examples

    (find-foreign-library '("libmysqlclient" "libmysql")
         '("/opt/mysql/lib/mysql/" "/usr/local/lib/" "/usr/lib/" "/mysql/lib/opt/")
         :types '("so" "dll")
         :drive-letters '("C" "D" "E"))
    => #P"D:\\mysql\\lib\\opt\\libmysql.dll"

### Side Effects

None.

### Affected by

None.

### Exceptional Situations

None.