4 Working Beyond the Lisp Environment
Ais 41 in C; in Liquid Common Lisp, the hexadecimal form of the same character is 4116 (in LCL/RS6000, it is 4138). Thus, to communicate with code compiled in another language, the Lisp data must be converted to a representation that the other language can understand. A similar conversion must take place when foreign code communicates with compiled Lisp code.
Liquid Common Lisp provides a Foreign Function Interface that allows you to link compiled C, Pascal, and FORTRAN files with a Lisp program and to link Lisp programs into running C, Pascal, and FORTRAN code. In this chapter, functions that are written in computer languages other than Lisp are called foreign functions.
The following features are provided by the Foreign Function Interface:
def-foreign-functiondefines a Lisp routine that coerces Lisp arguments to foreign data types, calls the foreign code, and coerces the values returned from the foreign code into Lisp objects.
def-foreign-callabledefines a routine that converts foreign arguments to Lisp objects, calls a Lisp routine, and converts the returned Lisp value into a foreign object.
def-foreign-structmanipulate a type system that is much like the Lisp type system but is applied to foreign data structures. Using this foreign type system, you can specify the layout of foreign data structures and write functions that convert between foreign data structures and Lisp objects.
load-foreign-librariesread binary object files into the Lisp image and build a symbol table of entry points.Unlike many linking loaders, all relocation information is preserved; thus, foreign code can be dynamically linked and relinked.
Generated with Harlequin WebMaker