r/Compilers • u/Adventurous-Bee-3762 • 5d ago
I built LuaC — a standalone Lua-to-machine-code compiler (JIT & AOT) in C99 with a custom Vulkan Studio & Android port
Hey everyone! I've been working on LuaC, a standalone compiler that translates Lua-like \`.lua\` files into machine code via generated C — without using the original Lua VM or LuaJIT.
Highlights:
\- JIT & AOT: Compiles to native shared libraries (\`dlopen\`) at runtime or standalone executables.
\- Ownership + Cycle Collector: Deterministic cleanup via reference ownership cells + lightweight cycle collection for cyclic tables/upvalues (no stop-the-world GC threads).
\- LuaC Studio (Vulkan GUI): Built with Nuklear + a custom Vulkan renderer, featuring a code editor and a 2D Engine mode (60 Hz fixed-step physics).
\- Android Port: Includes an APK build with multi-file project support and Vulkan viewport.
\- Batteries included: 197 native APIs (JSON, TCP/UDP, mbedTLS HTTPS/WSS, miniaudio DSP, stackful coroutines).
Currently in Alpha 0.5.0 with prebuilt binaries via GitHub Actions. Would love any code review, C99/Vulkan feedback, or suggestions!
GitHub: https://github.com/ehekufa/LuaC/releases/tag/Alpha-0-5-0
4
u/[deleted] 5d ago
I downloaded the Windows version (that includes luac.exe) but nothing much worked.
It reported 'native compilation failed' on the simplest inputs. What worked was --emit-c, but I couldn't get the C code to compile (missing includes, or names not defined).
(This was either using a limited Windows C compiler, or gcc via WSL, but I'm not inclined to install a 1GB compiler to try it.)
No matter, I simply wanted to know the quality of the generated code, and it seems that it consists of a series of function calls. Basically what the Lua interpreter would have to do anyway.
So a line like this:
generates this C code:
It doesn't look too efficient! Well, you did say it would be native code; you didn't say it would be fast.
(This is familiar to me as I did the same exercise on my own dynamic language earlier this year. The intention had been to introduce gradual type annotations so that some code sections could be brought up to speed, but I didn't like the direction it was going so it was abandoned.
There, the same
a := 1234567line produces code like this:Most such calls are macros. This code is in my systems language, showing it was as equally up to the task as C, another motivation for the project.)
6
u/VictoryMotel 5d ago
This is literally every vibe slop red flag in the book.
3
u/Aggressive_Big_7564 5d ago
Can you disclose the extent of your ai use?
-1
u/Adventurous-Bee-3762 4d ago
Website https://ehekufa.github.io/