From d87dce61ec60a9fd465ced313f387340a123f51d Mon Sep 17 00:00:00 2001 From: jgarcia Date: Mon, 23 Oct 2006 17:14:21 +0000 Subject: [PATCH] New tiny example of FFI --- examples/ffi/ecl.lsp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 examples/ffi/ecl.lsp diff --git a/examples/ffi/ecl.lsp b/examples/ffi/ecl.lsp new file mode 100644 index 000000000..ee2394e3c --- /dev/null +++ b/examples/ffi/ecl.lsp @@ -0,0 +1,16 @@ +#| +Build and load this module with (compile-file "ecl.lsp" :load t) +|# +;; +;; With this other statement, we import the C function sin(), which +;; operates on IEEE doubles. Notice that we include the C header to +;; get the full declaration. +;; +(defun c-sin (x) + (ffi:clines "#include ") + (ffi:c-inline (x) (:double) :double "sin(#0)" :one-liner t)) +;; +;; We now use this function and compare with the lisp version. +;; +(format t "~%Lisp sin:~t~d~%C sin:~t~d~%Difference:~t~d" + (sin 1.0d0) (c-sin 1.0d0) (- (sin 1.0d0) (c-sin 1.0d0)))