Version: 4.2.2

FFI: PLT Scheme Foreign Interface

Eli Barzilay

 (require scheme/foreign)

The scheme/foreign library enables the direct use of C-based APIs within Scheme programs – without writing any new C code. From the Scheme perspective, functions and data with a C-based API are foreign, hence the term foreign interface. Furthermore, since most APIs consist mostly of functions, the foreign interface is sometimes called a foreign function interface, abbreviated FFI.

Important: Many of the bindings documented here (the ones in sections with titles starting “Unsafe”) are available only after an (unsafe!) declaration in the importing module.

    1 Overview

    2 Loading Foreign Libraries

      2.1 Unsafe Library Functions

    3 C Types

      3.1 Type Constructors

      3.2 Numeric Types

      3.3 Other Atomic Types

      3.4 String Types

        3.4.1 Primitive String Types

        3.4.2 Fixed Auto-Converting String Types

        3.4.3 Variable Auto-Converting String Type

        3.4.4 Other String Types

      3.5 Pointer Types

      3.6 Function Types

        3.6.1 Custom Function Types

      3.7 C Struct Types

      3.8 Enumerations and Masks

    4 Pointer Functions

      4.1 Unsafe Pointer Operations

      4.2 Unsafe Memory Management

    5 Miscellaneous Support

      5.1 Unsafe Miscellaneous Operations

    6 Derived Utilities

      6.1 Tagged C Pointer Types

        6.1.1 Unsafe Tagged C Pointer Functions

      6.2 Safe C Vectors

        6.2.1 Unsafe C Vector Construction

      6.3 SRFI-4 Vectors

    7 Unexported Primitive Functions

    8 Macros for Unsafety