Live data from Hacker News

Lua for Elixir

davelucia.com

51–60 of 86 posts

Re: Lua for Elixir

#51

what is the Lua equivalent for JVM ecosystem? An embeddable language which you allows for running user scripts in a sandbox?

LuaJ, or Luna if you're brave. You can likely achieve something similar with other languages that runs on the JVM, like Kawa, Clojure or Jython.

Re: Lua for Elixir

#52

I've been considering adding Lua support to Keila for a while already. It seems like a perfect fit for when I'm going to implement email automation and want to allow custom business logic. This would certainly make that plan easier. Thanks OP for sharing the library with the community!

Let me know if you have any questions, I'd be happy to assist

Re: Lua for Elixir

#53
post #42

davydog187, I just wanted to thank you for stepping up and lending Robert a hand. It's nice to see new releases and lots of cleanups happening in Luerl. The project is a real gem and it's nice to see new activity in it!

Thanks, I really appreciate that. While its not my main focus by any means, its been a really fun project to chip away at (both the higher level library and Luerl itself).

I do think that it has the potential to be really great with continued investment

Re: Lua for Elixir

#54
post #20

Is this influenced by "Embedding Python in Elixir"? https://dashbit.co/blog/running-python-in-elixir-its-fine It certainly is more attractive in implementation. Well done!

Both the Lua library and Luerl predate Pythonx. I started this library nearly 2 years ago, its only now that I'm releasing a stable version.

However, Pythonx was originally created by a member of our team, Cocoa, who built it in her own free time. The Livebook team forked her project, conceptually, and released it.

https://github.com/cocoa-xu/pythonx

Re: Lua for Elixir

#56

Cool project, congrats. I am trying to understand why would anyone prefer to use Lua to create script instead of Elixir, which supports running scripts. While Lua has lots of users the language just have too many wrong design choices. If I had the choice between Elixir and Lua for scripts I would use Elixir every time.

Elixir is not a sandboxed language, so you can't just accept arbitrary Elixir programs from users and execute them inside of your application without security concerns. Lua, on the other hand, can be executed in a sandboxed fashion, limiting and constraining the reach of user programs.

Check out Anthony Accomazzo's post about Mini-Elixir, which does a great job breaking this down much further https://blog.sequinstream.com/why-we-built-mini-elixir/

Re: Lua for Elixir

#57
post #45

Earlier quoted context omitted.

I tend to build my prototypes as single file Elixir scripts. These are sometimes rather bulky with a bunch of logic and IO modules with some helper modules on the side. It's only when I believe in the idea that I reach for phx_new and start writing tests and copying in code into a full Phoenix project. When I started out with Phoenix I learned a lot from studying the boilerplate it can generate. If you just need a ro…

I typically use specific flags to "mix phx.new" that gets rid most of the files, especially JavaScript and whatnot. I am not at my PC right now and I forgot the flags, but I am sure you know what I am referring to. I never tried starting with Elixir scripts, I will give that a try.

Someone linked the Plug docs elsewhere in this subthread, those show you how you can quickly launch a web server from a single file, including one with WebSocket capability.

In my opinion Elixir scripts punch way above their weight. It's trivial to pull in the same dependencies as you would in a full project and you can easily keep a set of five or ten template scripts just laying around and copy those when you want a quick start with some boilerplate for a set of dependencies that often comes in handy. You could do something similar with mix plugins but it requires a bit more effort.

Re: Lua for Elixir

#59
post #20

Is this influenced by "Embedding Python in Elixir"? https://dashbit.co/blog/running-python-in-elixir-its-fine It certainly is more attractive in implementation. Well done!

Both the Lua library and Luerl predate Pythonx. I started this library nearly 2 years ago, its only now that I'm releasing a stable version. However, Pythonx was originally created by a member of our team, Cocoa, who built it in her own free time. The Livebook team forked her project, conceptually, and released it. https://github.com/cocoa-xu/pythonx

Very cool, thank you both for your contributions!

Re: Lua for Elixir

#60
This is so cool. A key benefit is that it's not embedding the C Lua runtime and compiler, but rather implements Lua in the host language (Elixir/Erlang).

When sandboxing user code in another runtime, you need to serialize the data to and from that runtime. That comes with a performance penalty.

So, for example, if you sandbox code in WASM, you need to pick a transport data format, like JSON. You need to serialize Elixir data structures into JSON, send it to WASM, and then deserialize the result. For a high-performance data pipeline, this adds up!

But if your sandbox is in the host language, no serialization/de-serialization is required. You can execute the sandboxed language in microseconds.

I wrote more about this here: https://blog.sequinstream.com/why-we-built-mini-elixir/

Wish this library existed just a couple months ago!

Post reply on HN