rlua -- High level bindings between Rust and Lua

Build Status Latest Version API Documentation

Guided Tour

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

rlua is NOT designed to be a perfect zero cost wrapper over the Lua C API, because such a wrapper cannot maintain the safety guarantees that rlua is designed to have. Every place where the Lua C API may trigger an error longjmp in any way is protected by lua_pcall, and the user of the library is protected from directly interacting with unsafe things like the Lua stack, and there is overhead associated with this safety. However, performance is a focus of the library to the extent possible while maintaining safety, so if you encounter something that egregiously worse than using the Lua C API directly, or simply something you feel could perform better, feel free to file a bug report.

There are currently a few missing pieces of this API:

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

API stability

This library is very much Work In Progress, so there is a some API churn. Currently, it follows a pre-1.0 semver, so all API changes should be accompanied by 0.x version bumps.

Safety and panics

The goal of this library 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". Still, I am not currently aware of any way to cause UB, and UB is considered the most serious kind of bug, so if you find the ability to cause UB with this API at all, please file a bug report.

Another goal of this library is complete protection from panics and aborts. Currently, it should not be possible for a script to trigger a panic or abort (with some important caveats described below). Similarly to the safety goal, there ARE several internal panics and even aborts in rlua source, but they should not be possible to trigger, and if you trigger them this should be considered a bug.

Caveats to the panic / abort guarantee:

Yet another goal of the library is to, in all cases, safely handle panics generated by Rust callbacks. Panic unwinds in Rust callbacks should currently be handled correctly -- the unwind is caught and carried across the Lua API boundary as a regular Lua error in a way that prevents Lua from catching it. This is done by overriding the normal Lua 'pcall' and 'xpcall' with custom versions that cannot catch errors that are actually from Rust panics, and by handling panic errors on the receiving Rust side by resuming the panic.

rlua should also be panic safe in another way as well, which is that any Lua instances or handles should remain usable after a user triggered panic, and such panics should not break internal invariants or leak Lua stack space. This is mostly important to safely use rlua types in Drop impls, as you should not be using panics for general error handling.

In summary, here is a list of rlua behaviors that should be considered a bug. If you encounter them, a bug report would be very welcome: