NextPrevUpTopContentsIndex

process-foreign-code

Macro

Summary

Compiles and loads C code, or allows it to be included in a Lisp fasl file, in 32-bit LispWorks on Solaris and HP-UX.

Package

foreign-parser

Syntax

process-foreign-code c-string &key language control =>

Arguments

c-string

A string.

language

One of :c or :ansi-c .

control

One of :fasl , :object or :source .

Description

c-string is a string containing C source code.

language is :c by default.

If control is :fasl , the C code is compiled at Lisp compile-file time into a temporary .o file. The resulting object module is stored in the fasl file. If the value is :object , the C code is compiled at compile-file time into a .o file with the same name as the Lisp source file, and loaded when the fasl file is loaded. If the value is :source , compilation and loading of the C code is done when the macro function is evaluated. The default value of control is :fasl .

Note: process-foreign-code is implemented only in 32-bit LispWorks on Solaris and HP-UX.

Note: The Foreign Parser is loaded by:

(require "foreign-parser")

Example

When this statement is evaluated the C code is compiled and also loaded into the image:

(foreign-parser:process-foreign-code
         "int sum (int a, int b) 
           { return a+b; } "
        :control :source)

The C function can be called from Lisp in the usual way:

(fli:define-foreign-function sum
    ((a :int)
     (b :int))
  :result-type :int)
 
(sum 2 3) => 5

See also

define-foreign-function
link-load:read-foreign-modules in the LispWorks Reference Manual .


LispWorks Foreign Language Interface User Guide and Reference Manual - 14 Mar 2008

NextPrevUpTopContentsIndex