rlua -- High level bindings between Rust and Lua

Build Status

WIP API Documentation

This library is a WIP high level interface between Rust and Lua. Its major goal is to expose as easy to use, practical, and flexible of an API between Rust and Lua as possible, while also being completely safe.

There are other high level Lua bindings systems for rust, and this crate is an exploration of a different part of the design space. The main high level interface to Lua right now is hlua which you should definitely check out and use if it suits your needs. This crate has the following differences with hlua:

The key difference here is that rlua handles rust-side references to Lua values in a fundamentally different way than hlua, more similar to other Lua bindings systems like Selene for C++. Values like LuaTable and LuaFunction that hold onto Lua values in the Rust stack, instead of pointing at values in the Lua stack, are placed into the registry with luaL_ref. In this way, it is possible to have an arbitrary number of handles to internal Lua values at any time, created and destroyed in arbitrary order. This approach IS slightly slower than the approach that hlua takes of only manipulating the Lua stack, but this, combined with internal mutability, allows for a much more flexible API.

There are currently a few notable missing pieces of this API:

Additionally, there are ways I would like to change this API, once support lands in rustc. For example:

It is also worth it to list some non-goals for the project:

API stability or lack thereof

This library is very much Work In Progress, so there is a lot of API churn. I think the library MIGHT be stable and usable enough to realistically use in a real project, but I cannot yet provide a stable API. I currently follow "pre-1.0 semver" (if such a thing exists), but there have been a large number of API version bumps, and there will probably continue to be. If you have a dependency on rlua, you might want to consider adding a 0.x version bound.

Safety and panics

My goal is complete safety, it should not be possible to cause undefined behavior whatsoever with the API, even in edge cases. There is, however, QUITE a lot of unsafe code in this crate, and I would call the current safety level of the crate "Work In Progress". If you find the ability to cause UB with this API at all, please file a bug report.

There are, however, a few ways to cause panics and even aborts with this API. I'm going to describe a lot of the finer points of panic handling in the library here, but again this should all be taken currently to be "Work In Progress".

Panic / abort considerations when using this API:

Examples

There's sort of a guided tour of the API here.