Mosh provides a general Foreign Function Interface (FFI) methods.
With these methods, you can load shared library, call C-function in it and get a result of function call.
FFI is not supported on Windows.
;; use mysql client library (let* ([libmysqlclient (open-shared-library "libmysqlclient.so.15")] [mysql-init (c-function libmysqlclient void* mysql_init void*)]) (display (mysql-init 0)))
;; generate png image with Cairo library. (import (rnrs) (mosh ffi)) (let* ((libcairo (open-shared-library "libcairo.so")) (cairo-image-surface-create (c-function libcairo void* cairo_image_surface_create int int int)) (cairo-surface-write-to-png (c-function libcairo int cairo_surface_write_to_png void* char*)) (cairo-create (c-function libcairo void* cairo_create void*)) (set-line-width (c-function libcairo void cairo_set_line_width void* double)) (rgba (c-function libcairo void cairo_set_source_rgba void* double double double double)) (move-to (c-function libcairo void cairo_move_to void* double double)) (line-to (c-function libcairo void cairo_line_to void* double double)) (TOY-show-text (c-function libcairo void cairo_show_text void* char*)) (stroke (c-function libcairo void cairo_stroke void*))) (let* ((surface (cairo-image-surface-create 1 300 300)) (ctx (cairo-create surface))) (rgba ctx 1.0 1.0 1.0 1.0) (set-line-width ctx 8.0) (move-to ctx 10.0 10.0) (line-to ctx 10.0 290.0) (line-to ctx 290.0 290.0) (line-to ctx 290.0 10.0) (line-to ctx 10.0 10.0) (move-to ctx 100.0 150.0) (TOY-show-text ctx "mosh") (stroke ctx) (display (cairo-surface-write-to-png surface "test.png"))))
Foreign Function Interface | Mosh provides a general Foreign Function Interface (FFI) methods. |
(mosh ffi) | Foreign Function Interface Library |
Functions | |
ffi-supported? | Returns #t when ffi is supported, otherwise #f. |
pointer->string | Returns string value at which pointer points. |
pointer-ref | Refer the value of pointer[index]. |
open-shared-library | Open shared library. |
c-function | Make foreign c-function closure. |
Constants | |
sizeof: | sizeof(bool) |
sizeof: | sizeof(short) |
sizeof: | sizeof(int) |
sizeof: | sizeof(long) |
sizeof: | sizeof(void*) |
sizeof: | sizeof(size_t) |
alignof: | struct x { char y; bool z; }; |
alignof: | struct x { char y; short z; }; |
alignof: | struct x { char y; int z; }; |
alignof: | struct x { char y; long z; }; |
alignof: | struct x { char y; void* z; }; |
alignof: | struct x { char y; size_t z; }; |
alignof: | struct x { char y; float z; }; |
alignof: | struct x { char y; double z; }; |
alignof: | struct x { char y; int8_t z; }; |
alignof: | struct x { char y; int16_t z; }; |
alignof: | struct x { char y; int32_t z; }; |
alignof: | struct x { char y; int64_t z; }; |
on-darwin | |
on-linux | |
on-freebsd | |
on-openbsd | |
on-windows |
Foreign Function Interface Library
Functions | |
ffi-supported? | Returns #t when ffi is supported, otherwise #f. |
pointer->string | Returns string value at which pointer points. |
pointer-ref | Refer the value of pointer[index]. |
open-shared-library | Open shared library. |
c-function | Make foreign c-function closure. |
Constants | |
sizeof: | sizeof(bool) |
sizeof: | sizeof(short) |
sizeof: | sizeof(int) |
sizeof: | sizeof(long) |
sizeof: | sizeof(void*) |
sizeof: | sizeof(size_t) |
alignof: | struct x { char y; bool z; }; |
alignof: | struct x { char y; short z; }; |
alignof: | struct x { char y; int z; }; |
alignof: | struct x { char y; long z; }; |
alignof: | struct x { char y; void* z; }; |
alignof: | struct x { char y; size_t z; }; |
alignof: | struct x { char y; float z; }; |
alignof: | struct x { char y; double z; }; |
alignof: | struct x { char y; int8_t z; }; |
alignof: | struct x { char y; int16_t z; }; |
alignof: | struct x { char y; int32_t z; }; |
alignof: | struct x { char y; int64_t z; }; |
on-darwin | |
on-linux | |
on-freebsd | |
on-openbsd | |
on-windows |
Make foreign c-function closure.
(c-function lib ret func . arg)
lib | library object returned by open-shared-library |
ret | return type of c-function. void*, char*, void, double and int are supported. |
func | name of c-function as symbol |
arg | list of argument types. void*, int, double and char* are supported. |
Foreign function closure