ValorZard

ValorZard

Would it be possible to embed the BEAM in a C/C++ app?

Hey all! New to the BEAM and Beam related languages, but it overall seems really cool. I’m still working my way through the tutorials, but a thought popped into my head that I can’t seem to shake off. Would it be possible to embed the BEAM/OTP into a c/c++ program?

I’m really into game development, so it would be cool to have a thing c++ layer covering graphics or whatever, but have most of the logic be done in Elixir itself. I know that a bunch of games already use Elixir in the backend, but it would be nice to only have to use one language to write everything, and not have a separate language for the client.

I did some research into this topic and found out about Elixir desktop and Liveview Native, which was able to get the BEAM embedded within Kotlin for Android and Swift for IOS, so this idea does seem possible, I just have no idea how it would work.

Would it be possible, for example, to compile the BEAM as a library for a c program using SDL2 to link against, or is there a better/easier way to do this?

Most Liked

wojtekmach

wojtekmach

Hex Core Team

That’s exactly what ElixirKit (at the moment part of the Livebook repo, livebook/elixirkit at v0.14.0 · livebook-dev/livebook · GitHub). It embeds your Elixir app inside your macOS and Windows app using Swift and C# APIs, respectively.

Edit: oops, to be specific at the moment, it starts the VM is separate OS process and communicates with it over TCP. See Elixir Desktop for example where the GUI and the VM run in the same OS process, a requirement for iOS for example.

D4no0

D4no0

I think you got it wrong, the way to do this is the other way around, you run c/c++ code from erlang VM.

This kind of integration is not much different from how any other language integrates with C, in erlang you have NIFs and Ports as the main tools to interact with other programming languages.

I don’t know how IOS integration works, however on android you don’t embed kotlin into erlang vm, you actually have the android runtime and erlang VM running at the same time, using a channel to communicate between each-other.

You can’t, the runtime was never meant to be run as a library from other application code, it lacks a lot of prerequisites to do so. The way to do this is to use erlang VM as your runtime and run c/c++ code from there with the tools mentioned above, or to separate them entirely and set a communication channel between them.

linusdm

linusdm

Welcome! Your question made me think of another thread that had some activity lately: OpenGL-rendered Breakout clone in Elixir

These people tried to approach game development on the BEAM, from another angle.

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement