On this page:
define-ffi-definer
make-not-available
provide-protected
5.6.1 FFI Identifier Conventions
convention:  hyphen->underscore
convention:  hyphen->camelcase

5.6 Defining Bindings 🔗

 (require ffi/unsafe/define) package: base

syntax

(define-ffi-definer define-id ffi-lib-expr
  option ...)
 
option = #:provide provide-id
  | #:define core-define-id
  | #:default-make-fail default-make-fail-expr
  | #:make-c-id make-c-id
Binds define-id as a definition form to extract bindings from the library produced by ffi-lib-expr. The syntax of define-id is

(define-id id type-expr
  bind-option ...)
 
bind-option = #:c-id c-id
  | #:c-id (unquote c-id-expr)
  | #:wrap wrap-expr
  | #:make-fail make-fail-expr
  | #:fail fail-expr
  | #:variable

A define-id form binds id by extracting a binding with the foreign name c-id from the library produced by ffi-lib-expr, where c-id defaults to id. The other options support further wrapping and configuration:

If provide-id is provided to define-ffi-definer, then define-id also provides its binding using provide-id. The provide-protected form is usually a good choice for provide-id.

If core-define-id is provided to define-ffi-definer, then core-define-id is used in place of define in the expansion of define-id for each binding.

If default-make-fail-expr is provided to define-ffi-definer, it serves as the default #:make-fail value for define-id.

For example,

(define-ffi-definer define-gtk gtk-lib)

binds define-gtk to extract FFI bindings from gtk-lib, so that gtk_rc_parse could be bound as

(define-gtk gtk_rc_parse (_fun _path -> _void))

If gtk_rc_parse is not found, then define-gtk reports an error immediately. If define-gtk is instead defined with

(define-ffi-definer define-gtk gtk-lib
   #:default-make-fail make-not-available)

then if gtk_rc_parse is not found in gtk-lib, an error is reported only when gtk_rc_parse is called.

Changed in version 6.9.0.5 of package base: Added #:make-c-id parameter.
Changed in version 8.4.0.5: Added #:variable option. Added unquote variant of #:c-id argument.

procedure

(make-not-available name)  procedure?

  name : symbol?
Returns a procedure that takes any number of arguments, including keyword arguments, and reports an error message from name. This function is intended for using with #:make-fail or #:default-make-fail in define-ffi-definer

Changed in version 8.3.0.5 of package base: Added support for keyword arguments.

syntax

(provide-protected provide-spec ...)

Equivalent to (provide (protect-out provide-spec ...)). The provide-protected identifier is useful with #:provide in define-ffi-definer.

5.6.1 FFI Identifier Conventions 🔗

 (require ffi/unsafe/define/conventions) package: base

This module provides several FFI identifier conventions for use with #:make-c-id in define-ffi-definer. A FFI identifier convention is any syntax transformer that converts one identifier to another.

Added in version 6.9.0.5 of package base.

syntax

convention:hyphen->underscore

A convention that converts hyphens in an identifier to underscores. For example, the identifier gtk-rc-parse will transform to gkt_rc_parse.

(define-ffi-definer define-gtk gtk-lib
  #:make-c-id convention:hyphen->underscore)
(define-gtk gtk-rc-parse (_fun _path -> _void))

syntax

convention:hyphen->camelcase

Similar to convention:hyphen->underscore, but converts the identifier to camel case instead, following the string-titlecase function. For example, the identifier camelCaseVariable will transform to came-case-variable.

(define-ffi-definer define-calib camel-lib
  #:make-c-id convention:hyphen->camelcase)
(define-calib camel-case-variable (_fun -> _void))