Comment by Andoryuuta

1 year ago

Is there something in specific that makes this easier to use in Rust projects compared to the Lua wrappers/bindings like mlua[0]? Or is it just an overall ergonomics thing?

Genuine question, as I don't have any prior experience embedding any scripting language into a Rust project.

[0]: https://github.com/mlua-rs/mlua

> By default mlua uses pkg-config tool to find lua includes and libraries for the chosen Lua version. In most cases it works as desired, although sometimes could be more preferable to use a custom lua library.

The fact that Rhai builds with just 'cargo build' shouldn't be underestimated - a Rust project with all pure-Rust dependencies is much easier to maintain / support / distribute across a wide variety of hosts!

  • This is just behind a feature flag like:

        $ cargo add mlua --features lua54,vendored
    
    

    Then mlua will statically build with the Lua sources it bundles itself and no need to link the system Lua or do anything other than "cargo build" like normal.

    • Still not as easy as pure Rust, e.g. for cross-compiling. It's similar to how pure Go projects are much easier to cross-compile than ones using cgo.

      `cargo cross` exists, which can help but it's really a kludge.

      5 replies →

Yes, it is designed for Rust, so the actual interop with Rust is very good. You can pass Rust types in and out with very little work, and they are represented in Rhai in a logical way.

Even something like a `Vec<u64>` is likely to be a right pain with Lua.

My frame: I would say that embedding in rust is hard, unless you are already thinking in rust. Mostly ownership things, which I see distinct from safety.

If you are thinking in rust already, why would you go to an FFI c solution?

(Source: have been prototyping DSLs in rust with most of my life force for about a year)