Stuart Tech
Published in

Stuart Tech

🏂 Ruby Bindings and Extensions

A practical guide to going native with C

Our Motivation

Aut inveniam viam aut faciam! (Find a way, or make one!) — Hannibal ⚔️

Getting Started

🔌 Part One — Native Extensions with Make Makefile

An example

Typical directory layout for MKMF.

Making sense of the C

Support Files

Building native extensions on gem install

🧲 Part Two — The Foreign Function Interface

What is H3?

It’s all about the hexagons!
Bees have long been exploiting the unique properties of regular hexagons.
From Uber’s H3 literature.

Building the bindings

The child hexagon (red) contained by its parent hexagon (green) at 1 resolution higher.

Custom Types

Complex Custom Types

Passing structs to C functions

“I don’t think we’re in Kansas any more, Toto.”

Pointers, Memory, and Arrays

Ice cream? Certainly, sir!
“I forgot to call free() !”

Using Pointers with FFI

Building nested structs

🎯 Putting it all together

Further reading

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sean Handley

Señor Developer specialising in open-source languages, particularly Ruby & Elixir. seanhandley.com