All Projects → paulcager → gerlang

paulcager / gerlang

Licence: Apache-2.0 license
Calling Go functions from Erlang

Programming Languages

go
31211 projects - #10 most used programming language
C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to gerlang

exor filter
Erlang nif for xor_filter. 'Faster and Smaller Than Bloom and Cuckoo Filters'.
Stars: ✭ 29 (+11.54%)
Mutual labels:  nif, erlang-nif
eapa
Erlang/Elixir Arbitrary-Precision Arithmetic (EAPA)
Stars: ✭ 36 (+38.46%)
Mutual labels:  nif
UIX-R
Ultima IX: Redemption for Morrowind and OpenMW
Stars: ✭ 32 (+23.08%)
Mutual labels:  nif
webview
Build cross platform desktop apps with Elixir and web technologies.
Stars: ✭ 18 (-30.77%)
Mutual labels:  nif
libsalty
Elixir bindings for libsodium (NIF)
Stars: ✭ 20 (-23.08%)
Mutual labels:  erlang-nif
better-dni
The fastest Spanish DNI (NIE / NIF) validation out there.
Stars: ✭ 23 (-11.54%)
Mutual labels:  nif
franz
A Kafka client library for Erlang/Elixir based on librdkafka implemented as a safe Rust NIF.
Stars: ✭ 30 (+15.38%)
Mutual labels:  nif
Rustler
Safe Rust bridge for creating Erlang NIF functions
Stars: ✭ 3,052 (+11638.46%)
Mutual labels:  nif
hyperbeam
Experimental NIF-based HTTP Server for the BEAM
Stars: ✭ 22 (-15.38%)
Mutual labels:  nif

gerlang

Calling Go functions from Erlang

April 2018: This is a work in progress.

The aim

Allow Erlang programs to call Go functions with minimum inconvenience.

It's certainly possible for an Erlang program to call a function written in Go, but it's frustratingly difficult. You must write an Erlang NIF in C, translate Erlang terms into Golang data structures, and then use CGO to call the Go function.

For many projects this overhead is too big, and most developers would just re-implement the Golang code in Erlang. The aim of this project is to make the process simple enough that calling Go from Erlang is easy.

How It Will Work

  • A generator program accepts a list of packages to be processed.
  • The generator produces everything that is needed to call the exported Go functions from Erlang:
    • An Erlang source module containing function definitions for each exported function and variable in the package.
    • A NIF to translate between Erlang terms and Golang data structures.
    • A shared object containing the compiled Golang packages, plus code to interact with the NIF.

What Didn't Work

https://punch.photoshelter.com/image/I0000ZvleumhOmDo

NIFs and Golang Plugins

This work is saved in branch nif-plugin-experiment.

  • An Erlang module (ergo) provided various functions to call into Go.
  • The Erlang module called out to a small NIF, which in turn called the Golang Call function.
  • Call looked up the target function (a named function within a Golang plugin) and translated Erlang parameters ("terms") into the types required by the Golang function.
  • The function was called, and its return value(s) converted back to Erlang terms.

This was abandoned because Golang does not support a Shared Object (-buildmode=c-shared) calling a Golang plugin.

Erlang Ports

An Erlang port is a common way to call out to external programs from Erlang, but is way too heavyweight for my purposes.

C Nodes and JInterface

Using a technique such as Erlang C Nodes or JInterface is an interesting idea, but doesn't fit in with the lightweight approach I'm looking for.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].