r/lua 6d ago

Help Help needed: Best Lua version/implementation for Rust integration and general scripting?

Hey everyone,

I'm trying to pick up Lua mainly for general scripting and embedding into Rust projects for things like config files. If I end up liking it as much as Rust, I'll probably dive deeper into it.

The main thing tripping me up is how many versions and runtimes exist out there (Lua 5.1, 5.4, LuaJIT, Luau, ...).

If anyone has experience embedding Lua in Rust (maybe using `mlua`), which version should I actually focus on learning? Also, are there any weird compatibility traps or gotchas I should watch out for?

Appreciate any advice or resources 🙏

11 Upvotes

10 comments sorted by

6

u/c__beck 6d ago

Lua JIT is a high performance JIT compiler locked to mainly 5.1, with some later features added. It’s used in a lot of game engines. Luau is a typed version of Lua used for Roblox coding.

If you’re looking for using Lua mainly for config files and other, non-speed critical use cases, there’s no reason to not use Lua 5.5 as it’s the latest and we’ll be the latest for about 5 years (that’s about how long each prior version lasted).

The benefit of using pure Lua is that it’s Lua. Once you know core/vanilla Lua can use most any Lua-based offshoot.

3

u/s0f4r 6d ago

This is a good answer. If you don't need luajit, easiest is just to avoid the version incompat problems and go with the latest version. 5.5.x is great for a starting point.

2

u/Old_County5271 5d ago edited 5d ago

I hate to say this but there's some extendable/scripting languages solutions strictly for rust that seem like a better choice than lua which is mostly C based (which is why I don't use them, but I am very curious).

3

u/lenscas 5d ago

Lua works perfectly fine in rust. Lua being written in C is not at all a problem for that?

1

u/wallstop-dev 6d ago

This is pretty hyper-specific to your use case. The differences between the major versions of Lua are not like, different languages, they just change some bits of functionality. Generally speaking, capability wise, you can solve pretty much the same types of problems across the entire Lua spec surface.

I'd recommend:

- Pick whatever library to interface with Lua you think you want to bet on

- Figure out what it supports

- Write Lua that it supports

And you're done. There's no wrong answer.

0

u/monolith_core 6d ago

Makes sense, keeps it simple. Appreciate the advice

1

u/CadmiumC4 5d ago

mlua allows you to pick the version you are embedding and it's a mandatory crate feature that needs to be picked

1

u/ALameLlama 1d ago

There is https://github.com/mlua-rs/mlua which is rust bindings for lua.

1

u/Additional-Elk-3712 22h ago

I use Lua (luau default) as scripting language for my Rust runtime using mlua-rs. its SpyWeb - a lightweight scraping/monitoring automation engine.

Lua 5.1 -> 5.4 version has some enhance and feature improvements, like < 5.3 Lua only has number type, while 5.3 and up has floating point and integer.

JIT version may have improve performance, though I never really benchmark them on my use case.

but there are noticeable difference bewteen standard Lua and Luau, like for Luau, it support type system and some feature are strip like io, os, package, debug which limit what it can do. and the reason I specifically use Luau as default as I need a sandbox environment for better security then just added my own package loader and fs support

So;

If you want the latest feature of Lua, just use 5.4

if you want JIT, you can only use 5.1 or 5.2

if you want type system support, you can use Luau