| 1 |
#| |
| 2 |
Build this module with (compile-file "uffi.lsp") |
| 3 |
Load it with (load "uffi.fas") |
| 4 |
|# |
| 5 |
;; |
| 6 |
;; This toplevel statement notifies the compiler that we will |
| 7 |
;; need this shared library at runtime. We do not need this |
| 8 |
;; statement in windows and macOS. |
| 9 |
;; |
| 10 |
#-(or windows darwin) |
| 11 |
(uffi:load-foreign-library "/lib64/libm.so.6") ;; adjust the library path/name as needed |
| 12 |
;; |
| 13 |
;; With this other statement, we import the C function sin(), |
| 14 |
;; which operates on IEEE doubles. |
| 15 |
;; |
| 16 |
(uffi:def-function ("sin" c-sin) ((arg :double)) |
| 17 |
:returning :double) |
| 18 |
;; |
| 19 |
;; We now use this function and compare with the lisp version. |
| 20 |
;; |
| 21 |
(format t "~%Lisp sin:~t~d~%C sin:~t~d~%Difference:~t~d" |
| 22 |
(sin 1.0d0) (c-sin 1.0d0) (- (sin 1.0d0) (c-sin 1.0d0))) |