AH2CL (Another Header to Common Lisp converter)

Ah2cl is a (very (very)) simple and naive C header parser.
It produce (at the moment) ffi (foreign function interface) for clisp and for uffi (but callbacks are well tested only with clisp and cmucl).


Source: ah2cl.lisp

Source + examples: ah2cl-0805.tar.gz or ah2cl-0805.zip


Ah2cl is under the LLGPL licence.
The code produced with ah2cl has no licence. So you can apply the licence of your choice to the produced code (But I'll be glad if you choose to share it as a free software).

Simple test: (With GNU/Linux, *nix)

A simple test is provided in the archive.

Go to test-ffi and compile the example:

$ cd test-ffi
$ make

this produce test and the shared library test.so

then fire your lisp and produce the ffi interface:

$ clisp or cmucl
> (load "../ah2cl.lisp")
> (ah2cl:parse-file "test.h"
                    :file-out "header.lisp"
                    :library "test.so"
                    :language :stdc
                    :ignored-keyword '("extern")
                    :write-original t
                    :package-name :header
                    :backend :both
                    :clisp-delimiter "#+CLISP"
                    :uffi-delimiter "#-CLISP")

this produce the file header.lisp from test.h/test.c as ffi interface.

And to use it:

> (load (compile-file "ffi-glue.lisp"))
> (load (compile-file "header.lisp"))
> (load (compile-file "test.lisp"))
> (test:start)
or simply:
> (load "load.lisp")

Have a look at test.lisp to see how to use C code.

Note: ffi-glue.lisp is here to enable callbacks in both clisp and cmucl/sbcl.
So if you want to use only clisp, you can safely replace def-callback with defun, callback with function and funcall-callback with funcall and ignore convert-array-to-pointer.

OpenGL/FreeGlut: (with *nix, GNU/Linux, Windows)

You can also produce ffi for OpenGL/FreeGlut:

$ cd test-openGL
$ make
$ cd opengl
$ clisp
> (load "produce-gl.lisp")
$ cd ..
$ clisp load.lisp or cmucl -load load.lisp

Have a look at produce-gl.lisp to see how to produce gl.lisp, glu.lisp, glut.lisp, glut-ext.lisp for CLisp
and/or gl-uffi.lisp, glu-uffi.lisp, glut-uffi.lisp, glut-ext-uffi.lisp for CMUCL
and at my-test.lisp to see how to use it.

Note: it needs some minor changes :

You can then try some OpenGL sample from here:
Load one of multiview.lisp, nii.lisp, null.lisp, starfield.lisp or maiden.lisp (ppms are here)
Some screenshots : CLisp GNU/Linux, CMUCL GNU/Linux, CLisp Windows.

(As an unofficial benchmarck, I got the same speed with CMUCL (71.5 FPS) and with the original C code (71.5 FPS) under GNU/Linux. CLisp is ~12% slower (62.5 FPS) on this plateform. But CLisp run the maiden demo ~50% faster than the CMUCL/C code under Windows (166.7 FPS)   =>   Conclusion: I have to improve my 3D card setting under GNU/Linux :) )

Have fun.

Thanks to:

Philippe Brochard
(format t "<~A@~A.~A>" '|hocwp| '|free| '|fr|)