Lua in Rust: Introduction
This begins a series dedicated to creating a JIT compiler for Lua 5.1 in Rust 1.35.
This is my first project in Rust, I’ve never used it before, so it’ll be full of mistakes and unidiomatic code. Also, I’m going to avoid using any 3rd party crate unless I absolutely have to: this is a project to learn Rust after all.
The repo is here.
The initial setup
The first thing to do is to setup reference implementation ideally with testing infrastructure. This makes it easy to compare custom implementation with the reference.
For the reference I’ve chosen Lua 5.1.5, Lua 5.1 test suite and LuaJIT 2.0.5 (to be used for performance comparison). Version numbers are chosen thus:
- LuaJit is at it’s latest (at the time of writing) and is claimed to support Lua 5.1
- Lua is the latest 5.1 release
- Lua test suite is also for 5.1
Here’s the state of the tree with all things imported.
Naturally, things didn’t work out from the get go. I had to make modifications to make things work and the majority of tests to pass:
- To make LuaJIT build on macOS I needed to change deployment target from the old 10.04 to 10.10.
- LuaJIT REPL outputs it’s header to stdout while Lua proper expect it to go to stderr. Fixed LuaJit by sending stuff to stderr.
- Lua on Linux uses readline which outputs to stdout everything from stdin. Tests are not expecting that. Fixed by turning readline off.
- Lua tests include native libraries which didn’t build on macOS.
- One test doesn’t pass on Lua proper, had to blacklist it, because I frankly don’t understand what’s going on.
- And quite a number of tests don’t pass on LuaJIT, blacklisted all of them: after all, LuaJit is only there to compete on performance.