a WIP ffi library for owl lisp
- libffi
- owl lisp compiled from source (new enough to have FP_API - tested with
*owl-version*
0.2.3a) - a local C compiler
(import
(owl toplevel)
(prefix (ffi) ffi/))
(λ (_)
(define-values (c-puts c-open c-write c-close)
(ffi/funcs (ffi/open-library "libc.so")
("puts" ffi/void ffi/pointer) ;; void puts(char*)
("open" ffi/int32 ffi/pointer ffi/int32) ;; int open(char*, int)
("write" ffi/uint32 ffi/int32 ffi/pointer ffi/uint32) ;; uint write(int, void*, uint)
("close" ffi/int32 ffi/int32))) ;; int close(int)
(c-puts "Hello, World!")
(let ((fd (c-open "/dev/stdout" 2))
(s "Hello, World from write(2)!\n"))
(c-write fd s (string-length s))
(c-close fd)))
then compile with
$ ol -x c -o file.c file.scm
$ cc -I/path/to/owl/source/c -DPRIM_FP_API -DPRIM_CUSTOM test.c ffi.c -lffi -ldl -o test
ffi.c
- the module code that gets injected into the vm that interacts with libffi and libdlffi.scm
- a user-friendly lisp front-end toffi.c
- probably won't run under owl-winrt because of the
dlopen
anddlsym
calls (might get ported some day)
this might be transformed into a extension if it turns out that they will stay in owl for good.