liveBook · Manning

Foreign function interface

As explained in Systems Programming with Zig

A foreign function interface is an interface that allows code written in one programming language to call or interoperate with code written in another.

A foreign function interface (FFI) lets code in one language interoperate with code in another. A PHP application can use a dynamic library, while Zig code speaks the C ABI—the rules systems libraries use to expose functions and data. section 5.1 section 5.7

A recipe-book backend

For a weekend recipe-book project, a PHP web application can call a Zig library through the C ABI rather than requiring its builder to learn PHP backend development. The library needs an API to create a book, create, delete, and list recipes, access recipe data, and save or load books. section 5.1

How Systems Programming with Zig covers it

How deep it goes
Defines FFI through a PHP–Zig project and identifies C ABI compatibility, without detailing call mechanics.
Examples
Uses a recipe-book backend whose API creates, retrieves, lists, deletes, saves, and loads recipes.
What you can do after
Build a cross-language library by exposing Zig code through the C ABI for a PHP application.
How it connects
Connects PHP, Zig, dynamic libraries, and the C ABI in a cross-language application.

Also explained in

Compare how 4 books explain foreign function interface →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Systems Programming with Zig. The section links point to the parts of the book it draws on.