Lua for Elixir

https://news.ycombinator.com/rss Hits: 7
Summary

The first stable release of the Elixir library, Lua v0.1.0, has been released to hex.pm! Lua is a library that allows you to execute arbitrary, sandboxed Lua programs directly on the BEAM VM. This is not embedding the C Lua runtime and compiler, but rather a complete implementation of Lua 5.3. This feat is made possible by the underlying Luerl library, which implements a Lua parser, compiler, and runtime, all in Erlang. The Lua Elixir library extends the capabilities of the Luerl library, improving error messages and providing robust documentation. Feature highlights include: Extending Lua with Elixir APIs The Lua Elixir library has a deflua macro for easily expressing APIs in Elixir that can be exposed to Lua with Lua.load_api/2 defmodule MyAPI do use Lua.API deflua double(v), do: 2 * v end import Lua, only: [sigil_LUA: 2] lua = Lua.new() |> Lua.load_api(MyAPI) {[10], _} = Lua.eval!(lua, ~LUA[return double(5)]) Compile-time syntax evaluation A ~LUA sigil is exposed, allowing the validation of Lua syntax at Elixir compile time. iex> import Lua, only: [sigil_LUA: 2] #iex> {[4], _} = Lua.eval!(~LUA[return 2 +]) ** (Lua.CompilerException) Failed to compile Lua! Robust documentation See the Lua Hex docs for detailed documentation and examples for working with Lua and Luerl. A Livebook is also available to get you started. Born at TV Labs The Lua Elixir library started as a proof of concept at TV Labs, where I am co-founder and CTO. At TV Labs, we needed to execute arbitrary code to allow our customers to write high-level integration tests against physical televisions and other streaming media devices. What started as a prototype led to diving deep into the particulars of Luerl, improving its usability and error messages, while making it easy to use from Elixir. TV Labs uses Lua as a compilation target for its drag and drop Automation builder, where users can specify the high-level workflow of their tests, and we handle the scheduling and underlying execution. The Elixir...

First seen: 2025-05-15 13:39

Last seen: 2025-05-15 19:40