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
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
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
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.







