On this page:
Rhombus FFI:   Foreign-Function Interface
0.45+9.2.0.3

Rhombus FFI: Foreign-Function Interface🔗ℹ

 import: ffi open package: rhombus-ffi-lib

The ffi library enables direct use of foreign libraries that have a C-based API—without writing any new C code. From the Rhombus 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.

    1 Overview

      1.1 Unsafety of Foreign Functions

      1.2 Foreign-Function Basics

        1.2.1 Loading C Libraries

        1.2.2 Finding C Functions

        1.2.3 Increasing Safety with Tagged Pointers

        1.2.4 Reducing Boilerplate for Function Definitions

        1.2.5 Defining a Type Conversion

        1.2.6 Putting it All Together

      1.3 Composite Foreign Data

        1.3.1 Array Arguments

        1.3.2 C Structs

        1.3.3 Callbacks from C to Rhombus

      1.4 Memory Management

        1.4.1 Reliable Release of Resources

        1.4.2 Pointers and GC-Managed Allocation

      1.5 Foreign Unions and Pointer Arithmetic

        1.5.1 Declaring Union Types

        1.5.2 Hiding Pointers through Conversion

    2 Reference

      2.1 Foreign Libraries

      2.2 Base Foreign Types

      2.3 Compound Foreign Types

      2.4 Defining Foreign Types

      2.5 Foreign Pointers

      2.6 Foreign Functions

    3 Additional FFI Libraries

      3.1 Finalization

      3.2 Atomic Mode and Uninterruptible Mode