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. |
shared-errno | When invoked with no argument, returns errno (On Windows getLastError()). |
pointer? | Returns #t if obj is pointer, otherwise #f |
pointer->integer | convert pointer to integer |
pointer->string | Returns string value at which pointer points. |
open-shared-library | Open shared library. |
c-function | Make foreign c-function closure. |
pointer-ref-c-uint16 | Get a value from pointer + offset as uint16. |
pointer-ref-c-uint32 | Get a value from pointer + offset as uint32. |
pointer-ref-c-uint64 | Get a value from pointer + offset as uint64. |
pointer-ref-c-int8 | Get a value from pointer + offset as int8. |
pointer-ref-c-int16 | Get a value from pointer + offset as int16. |
pointer-ref-c-int32 | Get a value from pointer + offset as int32. |
pointer-ref-c-int64 | Get a value from pointer + offset as int64. |
pointer-ref-c-signed-char | Get a value from pointer + offset as signed-char. |
pointer-ref-c-unsigned-char | Get a value from pointer + offset as unsigned-char. |
pointer-ref-c-signed-short | Get a value from pointer + offset as signed-short. |
pointer-ref-c-unsigned-short | Get a value from pointer + offset as unsigned-short. |
pointer-ref-c-signed-int | Get a value from pointer + offset as signed-int. |
pointer-ref-c-unsigned-int | Get a value from pointer + offset as unsigned-int. |
pointer-ref-c-signed-long | Get a value from pointer + offset as signed-long. |
pointer-ref-c-unsigned-long | Get a value from pointer + offset as unsigned-long. |
pointer-ref-c-signed-long-long | Get a value from pointer + offset as signed-long-long. |
pointer-ref-c-unsigned-long-long | Get a value from pointer + offset as unsigned-long-long. |
pointer-ref-c-float | Get a value from pointer + offset as float. |
pointer-ref-c-double | Get a value from pointer + offset as double. |
pointer-ref-c-pointer | Get a value from pointer + offset as pointer. |
pointer-set-c-char! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-short! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-int! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-long! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-long-long! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-float! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-double! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-int8! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-int16! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-int32! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-int64! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-uint8! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-uint16! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-uint32! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-uint64! | Returns #t when ffi is supported, otherwise #f. |
Constants | |
size-of-bool | size-of(bool) |
size-of-short | size-of(short) |
size-of-int | size-of(int) |
size-of-long | size-of(long) |
size-of-void* | size-of(void*) |
size-of-pointer | alias for size-of(void*) |
size-of-size_t | size-of(size_t) |
align-of-bool | struct x { char y; bool z; }; |
align-of-short | struct x { char y; short z; }; |
align-of-int | struct x { char y; int z; }; |
align-of-long | struct x { char y; long z; }; |
align-of-void* | struct x { char y; void* z; }; |
align-of-size_t | struct x { char y; size_t z; }; |
align-of-float | struct x { char y; float z; }; |
align-of-double | struct x { char y; double z; }; |
align-of-int8_t | struct x { char y; int8_t z; }; |
align-of-int16_t | struct x { char y; int16_t z; }; |
align-of-int32_t | struct x { char y; int32_t z; }; |
align-of-int64_t | 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. |
shared-errno | When invoked with no argument, returns errno (On Windows getLastError()). |
pointer? | Returns #t if obj is pointer, otherwise #f |
pointer->integer | convert pointer to integer |
pointer->string | Returns string value at which pointer points. |
open-shared-library | Open shared library. |
c-function | Make foreign c-function closure. |
pointer-ref-c-uint16 | Get a value from pointer + offset as uint16. |
pointer-ref-c-uint32 | Get a value from pointer + offset as uint32. |
pointer-ref-c-uint64 | Get a value from pointer + offset as uint64. |
pointer-ref-c-int8 | Get a value from pointer + offset as int8. |
pointer-ref-c-int16 | Get a value from pointer + offset as int16. |
pointer-ref-c-int32 | Get a value from pointer + offset as int32. |
pointer-ref-c-int64 | Get a value from pointer + offset as int64. |
pointer-ref-c-signed-char | Get a value from pointer + offset as signed-char. |
pointer-ref-c-unsigned-char | Get a value from pointer + offset as unsigned-char. |
pointer-ref-c-signed-short | Get a value from pointer + offset as signed-short. |
pointer-ref-c-unsigned-short | Get a value from pointer + offset as unsigned-short. |
pointer-ref-c-signed-int | Get a value from pointer + offset as signed-int. |
pointer-ref-c-unsigned-int | Get a value from pointer + offset as unsigned-int. |
pointer-ref-c-signed-long | Get a value from pointer + offset as signed-long. |
pointer-ref-c-unsigned-long | Get a value from pointer + offset as unsigned-long. |
pointer-ref-c-signed-long-long | Get a value from pointer + offset as signed-long-long. |
pointer-ref-c-unsigned-long-long | Get a value from pointer + offset as unsigned-long-long. |
pointer-ref-c-float | Get a value from pointer + offset as float. |
pointer-ref-c-double | Get a value from pointer + offset as double. |
pointer-ref-c-pointer | Get a value from pointer + offset as pointer. |
pointer-set-c-char! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-short! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-int! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-long! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-long-long! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-float! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-double! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-int8! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-int16! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-int32! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-int64! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-uint8! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-uint16! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-uint32! | Returns #t when ffi is supported, otherwise #f. |
pointer-set-c-uint64! | Returns #t when ffi is supported, otherwise #f. |
Constants | |
size-of-bool | size-of(bool) |
size-of-short | size-of(short) |
size-of-int | size-of(int) |
size-of-long | size-of(long) |
size-of-void* | size-of(void*) |
size-of-pointer | alias for size-of(void*) |
size-of-size_t | size-of(size_t) |
align-of-bool | struct x { char y; bool z; }; |
align-of-short | struct x { char y; short z; }; |
align-of-int | struct x { char y; int z; }; |
align-of-long | struct x { char y; long z; }; |
align-of-void* | struct x { char y; void* z; }; |
align-of-size_t | struct x { char y; size_t z; }; |
align-of-float | struct x { char y; float z; }; |
align-of-double | struct x { char y; double z; }; |
align-of-int8_t | struct x { char y; int8_t z; }; |
align-of-int16_t | struct x { char y; int16_t z; }; |
align-of-int32_t | struct x { char y; int32_t z; }; |
align-of-int64_t | 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