louis's Blog

louis's Avatar Image
Software developer #Go #CommonLisp #JS #SQL. #LispWorks user. Soft spots for #Emacs #SmallWeb. Recently becoming #OpenBSD enthusiast.

Other hobbies: #Running #FireFighter #StarTrek
← All posts

Maybe a mix of C and CommonLisp can solve filling the gaps in missing libraries.

It’s actually that easy to talk to C from Common Lisp:

Example C function

int add(int a, int b) {
  return a + b;
}

Compiile as a shared library with GCC.

% gcc -c -Wall -Werror -fpic lib.c
% gcc -shared -o mylib.so lib.o

Locate your library and define a foreign function in Common Lisp (#LispWorks in this case):

(fli:register-module "mylib.so")

(fli:define-foreign-function
    (add "add" :source)
    ((a :int)
     (b :int))
    :result-type :int
    :language :ansi-c)

Enjoy the fruits:

(add 66 3)
> 69

#CommonLisp

To like or reply, open original post on Emacs.ch