A developer built a Lua compiler that turns scripts into native executables without a Lua VM
Trials and Tribulations of Native Lua Compilation
After years of embedding Lua, the author of clx wanted to go beyond packaging a VM inside an executable. clx parses Lua 5.5, generates C++, and compiles it with Clang, GCC, or MSVC, producing native code backed by a purpose-built runtime for tables, strings, GC, and coroutines. Modules, native C++ bindings, and static libraries all work, with an optional --dynamic mode for runtime-loaded scripts. The hard part wasn't code generation but preserving Lua's semantics.
The individual pieces are manageable, but making all of them behave correctly together is where the real work is.
- Philpax
This is of interest to me, but I have no idea why you'd set `height: 720px`. I had to turn that off to make it readable.
- drdexebtjl
> It also means that libraries written in C or C++ don't need to be translated into some special Lua-specific implementation. They can remain native libraries, with a thin clx binding layer exposing the functionality to Lua.
This is already true of upstream Lua implementations. It is very easy to write thin Lua binding layers to C libraries.
That is the entire point of Lua. It’s easy to call Lua from native code, and it’s easy to call native code back from Lua, so you can have call stacks that seamlessly interweave Lua and native code.
I’m very skeptical of the idea that this can unlock improvements in performance or size. We already have LuaJIT which is plenty fast, and PUC-Lua which is so small, it runs on MCUs.
- wiradikusuma
If it has to go through compilation process to make it native, doesn't that defeat the purpose of Lua? I mean, why not just use the same language of the host application, in other words, just another function/module of that app.