Skip to content

Getting Started

Rob "Hurricane" Ashton edited this page Mar 31, 2021 · 5 revisions

Pre-requisites

  • Erlang (OTP21+ please)
  • .NET Core 5.0.0+
  • g++/gcc/etc you know

Anyway...

Because we're working with two VMs, we needed to pick one to own the other. Erlang is older so wins through seniority (Ok, boomer).

The rough idea here is that we will

  • Create an assembly in dotnet, referencing the Erlang package
  • Implement either IApp or IApp<>
  • Create an Erlang Application, referencing the Erlang.NET package
  • Load the dotnet assembly into the Erlang Application and run the App

In dotnet

Create a dotnet library project using .NET 5.0, and add a reference to the package 'Erlang' (Found on Nuget).

dotnet add package Erlang --version 1.0.0

Define an entry point for your Erlang Application, the simplest one would be a single function returning a single value.

using Erlang;

namespace Acme {
  public class HelloWorld : IApp {
    public Object Start() {
      return "Hello World";
    }
  }
}

In Erlang

  • Add erlang.net to your rebar.config, master will do just fine
{deps, [
  {dotnet, {git, "http://github.com/robashton/erlang.net", {branch, "master"}}},
]}.
  • Add 'dotnet' to the list of applications to start in your app.src
  {applications, [
                  kernel,
                  stdlib,
                  dotnet
                 ]},

And now, from Erlang, we can invoke that application by writing the following line of code

  { ok, Result } = dotnet:run_app_from_assembly("path/to/MyAssembly.dll", "Acme.HelloWorld");
  io:format(user, "Result: ~p~n", [ Result ]);

The next thing you'll want to learn how to do is pass values to this application, thankfully there is a wiki page for that.

Clone this wiki locally