Nocturnal FFI (noffi) is a novel approach to use foreign libraries from Common Lisp. All that is needed to start addressing some foreign library is pointing noffi to the header file and the library. No bindings need to be written. This is possible because internally noffi works more like a C compiler than like a binding or wrapper generator.
noffi is used by means of the #_
reeder macro which is an
escape route to C.
(noffi:noffi-syntax) ;install #_ reader macro #_{#include <math.h>} ;make declarations from <math.h> known (#_cos pi) → 1.0D0 #_M_PI → 3.141592653589793D0 _#(#include <stdlib.h>} (#_div 42 11) → #_((div_t){ .quot = (int)3, .rem = (int)9 }) (let ((r (#_div 42 11))) (values (#_.quot r) (#_.rem r))) → 3; 9
get-c-string | pointer | Function |
Examples
#_{#include <stdlib.h>}
(get-c-string (#_getenv "HOME"))
→ "/Users/joe"
|
c-aref |
|
Accessor |
Dereferences the foreign pointer pointer at offset index (measured in elements). Hence when pointer points to C array it returns the indexth element. Examples#_{#include <stdlib.h>} (c-aref (#_getenv "HOME") 0) → 47 ; 47 is "/" (c-aref (#_getenv "HOME") 1) → 85 ; 85 is "U" |
use-include | header-name | Macro |
Arranges for the include file specified by
header-name to be parsed and its declarations been
known. The angle brackets Examples(use-include "<stddef.h>") |
pkg-use |
|
Macro |
Arranges to use a given pkg by means of
pkg-names is either a single pkg name or a list of
pkg names. Then follows either C material for
Examples(pkg-use "x11" "#include <X11/Xlib.h>") (pkg-use ("acme" "acme-extra") (:additional-config-args "--atleast-version=42") (:config-program "/opt/acme/acme-config") "#define ACME_SMALL" "#include <acme/acme.h>") |
*pkg-config-args* | Parameter |
Default list of additional command line arguments to the
|
ctypep |
|
Function | ||||
→ | generalized-boolean |
Arguments
DescriptionReturns true, if the object object is of a C type compatible to the C type ctype.
The environment argument specifies the environment to
use to find type definitions. The default Examples(ctypep 100 '#_<char>) → T (ctypep 1234 '#_<char>) → NIL (ctypep pi '#_<int>) → NIL (ctypep 3.14D0 '#_<double>) → T (ctypep "foo" '#_<char*>) → NIL #_{typedef struct foo { int x; } foo_rec, *foo_ptr;} (ctypep (c-make #_<struct foo>) '#_<struct foo *>) → T (ctypep (c-make #_<struct foo>) '#_<foo_ptr>) → T
Null Pointers are typeless, hence
(ctypep nil '#_<char *>)
→ T
Unions are not like union types in the mathematical sense:
(ctypep 100 '#_<union { int i; double d; }>)
→ NIL
Notes
In noffi due to its dynamically typed nature, two anonymous
|