Show HN: Lunar, a "fast", memory-efficient Lua 5.1 VM written in Go

github.com

7 points by drakenot 1 day ago

I'm releasing Lunar, a new Lua 5.1 compiler and virtual machine written entirely in Go. It includes the standard libraries, coroutines as well as supporting Lua 5.2-style goto.

The embedding API avoids the Lua C API’s stack-based interface in favor of typed Go values and callback frames. Libraries and script-file access are opt-in, so the host explicitly controls what Lua code can access.

On my current benchmarks and use-cases, Lunar is often ~1.5x to 2x faster than GopherLua and Shopify’s go-lua. Its largest improvement however is memory use: loading a 9 MB CBOR-derived object graph (hundreds of thousands of tables) allocates about 107 MB versus 785 MB with GopherLua, with roughly 72 MiB versus 542 MiB retained after GC.

The public API is still stabilizing, and I’d especially appreciate feedback on the embedding design and Go interface.

(Note that this project started in another repo when I still had hopes of porting some of my changes back upstream to another existing library.)

drakenot 1 day ago

For those who are interested in what spawned this project:

https://runemud.com

I had been working on it for a couple years, using it myself. I finally released it recently. It heavily uses an embedded Lua VM to power its scripting engine.

granganath 1 day ago

This looks really cool! I'm still early career, so I don't have much technical feedback to give, but starred and excited to learn how it works