amb85

amb85

Calling Elixir Scripts from within Rust

I’ve been thinking about how I could use Elixir as a scripting language within a Rust application. I read an interesting discussion about Rustler, NIFs and Ports, but this doesn’t quite seem to meet the use case I envision.

What I really want is a Rust application with the Erlang BEAM and Elixir embedded (probably when the Rust application is compiled?). Rust should be the main entry point and would initiate execution of the Elixir scripts, with any necessary results/changes being propagated back to the Rust app. (I guess think of something like a game engine written in C++ with an embedded Lua scripting engine).

I can think of a couple options where Rust an Elixir portions are their own processes and use Ports to communicate. Or where the Rust app launches some mix task and uses NIFs to access other Rust functionality. Both of these approaches seem clunky.

Has anyone got any thoughts or suggestions on how I might approach achieving such a goal?

Most Liked

hauleth

hauleth

I have one simple question - WHY?

I mean BEAM wasn’t designed as a embedded scripting engine, so it isn’t easy accessible as one. You can though look at the Enigma which is BEAM implementation in Rust, so maybe you could integrate that.

TBH If you want embedded language in Rust then look into Lua(JIT), Ketos, or Dyon.

tme_317

tme_317

You could potentially compile your elixir code as escripts, then just launch them from the Rust app sending necessary data as command line arguments or from stdin and reading the result from stdout.

This has some downsides and may not work or be performant enough depending on what you are trying to accomplish but it could work for you. Usually I do the opposite and launch fast Rust apps all the time from my main Elixir long-running app.

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

Other popular topics Top

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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

We're in Beta

About us Mission Statement