Lua for Elixir
Published on: 2025-07-06 12:03:51
Published May 12, 2025
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 sigi
... Read full article.