Zune: A luau runtime built & written with Zig

This is my first Zig project, and I wanted to create a luau runtime written in Zig, whilst also achieving the most amount of performance as a way to learn about Zig.

In short, zune is a luau runtime similar to how Bun is a JavaScript runtime.

Features:

  • Supports Linux, Windows, macOS, and FreeBSD.
  • A Test Runner backend for testing Luau code.
  • Bundling/Compiling into an executable.
  • Built-in Standard Libraries.
  • Built-in Debugger.
  • Types & docs for LSP.
  • Small Release Binary Size.

The networking backend, like HTTP client and server with TLS support, using ianic/tls.zig, is built entirely in zig and made particularly for zune, with the custom HTTP Server implementation reaching ~152k req/s on my machine (Ryzen 7 5800X, Linux, io_uring), single threaded, powered with a custom libxev fork.

In the process of making this project, I also worked on another library originally forked from ziglua, zig-luau (repository under the same zune organization), which is made for luau in Zig, porting some C++ code into Zig code, like most of the gc, mem, and lua C api, mainly to avoid C exceptions. This was also part of the performance goal: to compile code mostly with Zig.

15 Likes

Microsoft might still own a trademark (or other legal protection) on the name “Zune”.

3 Likes

The name and trademark were abandoned in 2010. I have checked this before landing on the name, unless I am mistaken, correct me if I am wrong.

5 Likes

Looks like the trademark is “DEAD APPLICATION Refused Dismissed or Invalidated” according to https://uspto.report/TM/88153817. Nice find for the name!

3 Likes

This is an amazing project! A whole runtime for the Luau language in Zig. I haven’t dived deep into it. Does it support garbage collection?

It should already come with garbage collection support, as it is part of luau, scripting language derived from Lua.

Trademarks are only enforceable if there’s a risk of consumer confusion. A Zig project (cool project!) is not an MP3 player, or enough like one to run the risk.

Nintendo isn’t going to sue me for zelda either, and that brand is quite actively maintained.

4 Likes

0.5.1

Bug Fixes

  • Fixed multi-threading deadlock after completion.
  • Fixed detailed error logs not previewing line up to EOF.
  • Fixed fs.watch error with absolute paths on windows.

Changes

  • Upgraded to Luau 0.695.
  • Upgraded to Zig 0.15.2.
4 Likes

0.5.2 was also released but not posted, changelogs would be bunched together in this post.

0.5.3

Bug Fixes

  • Fixed struct generation for C functions using an FFIStruct type.

  • Fixed FileHandle readSync/writeSync methods erroring on windows.

  • Fixed FileHandle seekFromEnd method not accepting negative number.

  • Fixed invalid TOML encoding for inline tables.

  • Fixed encoding nested arrays for TOML.

  • Fixed encoding array values for TOML.

  • Added tilde expression aliases support for home directory.

  • Fixed deadlock with scheduler multi-threaded synchronization.

  • Fixed lua stack overflow from zune API.

  • Fixed crashes from early resuming threads on some async API.

Changes

  • Upgraded to Luau 0.700
1 Like

This is incredibly cool, thanks for sharing! I’ve only just started playing with it, but Luau solves a lot of the problems I have with Lua (not 1-based indexes sadly), but I was torn between teel and Luau. You’ve made the choice for me :slight_smile: this is sick!

2 Likes