Miscellaneous Support

(regexp-replaces name substs)      PROCEDURE

A function that is convenient for many interfaces where the foreign library has some naming convention that you want to use in your interface as well. The first name argument can be any value that will be used to name the foreign object -- a symbol, a string, a byte string etc. This is first converted into a string, and then modified according to the given substs list in sequence, where each element in this list is a list of a regular expression and a substitution string. Usually, regexp-replace* is used to perform the substitution, except for cases where the regular expression begins with a ``^'' or ends with a ``$'' where regexp-replace is used.

For example, the following makes it convenient to define Scheme bindings such as foo-bar for foreign names like MyLib_foo_bar:

(define mylib (ffi-lib "mylib"))
(define-syntax defmyobj
  (syntax-rules (:)
    [(_ name : type ...)
     (define name
       (get-ffi-obj (regexp-replaces 'name '((#rx"-" "_") (#rx"^" "MyLib_")))
                    mylib (_fun type ...)))]))
(defmyobj foo-bar : _int -> _int)

(list->cblock list ctype)      PROCEDURE

Allocates a memory block of an appropriate size, and initializes it using values from list and the given ctype. The list must hold values that can all be converted to C values according to the given ctype.

(cblock->list cblock ctype length)      PROCEDURE

Converts C pointers cblock to vectors of ctype, to Scheme lists. The arguments are the same as in the list->cblock. length must be specified because there is no way to know where the block ends.

(vector->cblock vector ctype)      PROCEDURE

Same as the list->cblock function, only for Scheme vectors.

(cblock->vector cblock ctype length)      PROCEDURE

Same as the cblock->vector function, only for Scheme vectors.