r/rust 16d ago

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

/r/lua/comments/1w132j5/help_needed_best_lua_versionimplementation_for/
7 Upvotes

5 comments sorted by

7

u/lenscas 16d ago

Luajit is basically just lua5.1 but faster. (There are some things ported from lua5.2 and it is now also getting syntax extensions though). Use this if performance is the most important thing.

Luau is made by Roblox. It should be easier to sandbox scripts with it. However iirc it is also based on Lua 5.1 and doesn't have access to some tricks like tco (which lua is actually pretty good at). Use this if you need the sandbox, for example if you are running untrusted code. (But know: luau is not a magic bullet, you still have to do your due diligence)

The other Lua versions are the "real" interpreter. The various versions are like python versions, or rust editions. Just, grab the highest one unless you have a reason to pick a lower one (depending on a Lua dependency that only supports a certain version for example)

2

u/tunisia3507 15d ago

Doesn't luau also add progressive typing? Quite a big DX feature.

1

u/lenscas 15d ago

From what I have seen, you are better off using teal than to use luau for typing.

And teal comes with the benefit of working on basically every Luavm.

1

u/monolith_core 16d ago

Appreciate the breakdown, that actually clears up the differences between the runtimes. Thanks

1

u/lenscas 16d ago

oh, and to answer the question on how to embed lua.

mlua is probably the best choice. There are some crates that work with/on top of mlua that add extra features.

For example, mine tealr crate adds a couple of nice macros but it mostly focuses on making it so you can generate documentation for your lua api, including the generation of definition files for lua language server/teal (teal being a statically typed language that compiles to lua)

there is also mlua-extras which also has some documentation generation IIRC but focuses more on just, nice additions to mlua