Calling Foreign Functions with Pharo
✒️ By Esteban Lorenzano, Guillermo Polito and Stéphane Ducasse
This concise guide introduces the Unified FFI (uFFI) in Pharo, showing how to call C functions, work with external libraries, and manage callbacks. It’s perfect for Smalltalk developers or anyone looking to bridge Pharo with native code. The book uses clear examples and real-world scenarios, making complex topics accessible. Whether you’re new to FFI or want a quick reference, you’ll find practical tips and hands-on advice throughout.
Book Description
“Calling Foreign Functions with Pharo” is your go-to manual for mastering the Unified Foreign Function Interface (uFFI) in the Pharo programming environment. Written by Esteban Lorenzano, Guillermo Polito, and Stéphane Ducasse, this compact book packs a punch for anyone looking to connect Pharo with native code. If you’re a Smalltalk developer or simply curious about integrating C libraries into your projects, this guide will walk you through the essentials with clarity and a touch of humor.
The authors break down complex concepts into manageable steps. You’ll learn not only how FFI works in general but also how to apply it specifically within the Pharo ecosystem. With hands-on examples and practical advice, you’ll quickly gain confidence in calling C functions, managing memory, and handling tricky data types like structs and arrays. Even if you’ve never written an FFI binding before, this book makes the process approachableand maybe even fun.
Who is this book for? It’s ideal for developers already comfortable with Smalltalk or Pharo who want to extend their applications using native libraries. If you’re working on cross-platform software or need to squeeze out extra performance by leveraging C code, you’ll find this guide invaluable.
What You Will Learn
- How to call external C functions from Pharo using uFFI
- Binding Smalltalk methods to native library functions
- Passing arguments (including strings, variables, and literals) between Pharo and C
- Handling return values from native code
- Working with pointers, structures, arrays, and callbacks
- Managing platform differences (Linux, MacOS, Windows)
- Troubleshooting common FFI issues
The book covers everything from simple function calls to more advanced topics like callbacks and memory management. You’ll also get practical guidance on adapting your bindings for different operating systemsa must-have skill for cross-platform development.
If you’re interested in exploring more about integrating external code or enhancing your workflow in Smalltalk environments, don’t miss our resources on Pharo programming best practices and using external libraries in Smalltalk. These guides complement what you’ll learn here and help you build robust applications faster.

Leave a Reply
You must be logged in to post a comment.