7.7
ffi-definer-convention: augments define-ffi-definer
(require ffi-definer-convention) | |
package: ffi-definer-convention |
This module overrides the define-ffi-definer form from ffi/unsafe/define to allow the use of naming conventions that translate from Racket identifiers to C identifiers.
syntax
(define-ffi-definer define-id ffi-lib-expr option ...)
option = other-options | #:make-c-id make-c-id-expr
Overrides the define-ffi-definer form, adding a new keyword argument #:make-c-id.
When make-c-id-expr is provided, its result is called to create
an identifier argument that is provided for the #:c-id keyword
argument of the defined definer. This function expression is evaluated
at syntax phase (phase level 1).
Examples:
> (begin-for-syntax (define (prefix-scheme id) (format-id id "scheme_~a" (syntax-e id))) (define (hyphen->underscore id) (format-id id (string-replace (symbol->string (syntax-e id)) "-" "_"))))
> (define-ffi-definer define-rkt #f #:make-c-id (compose prefix-scheme hyphen->underscore)) > (define-rkt get-milliseconds (fun -> int)) > (get-milliseconds) -636074773
procedure
id : identifier?
procedure
id : identifier?
procedure
id : identifier?
These functions are intended for use with the #:make-c-id
keyword argument for define-ffi-definer. They encode common
naming conventions for foreign functions.
All of these functions are provided at syntax phase (phase level 1).
Example:
> (begin-for-syntax (displayln (convention:hyphen->underscore #'hello-world)) (displayln (convention:hyphen->camelcase #'hello-world)) (displayln (convention:prefix-scheme #'hello_world)))
#<syntax hello_world>
#<syntax HelloWorld>
#<syntax scheme_hello_world>