flu 0.0.2

Lua 5.1 framework for Rust
Documentation
  • Coverage
  • 0%
    0 out of 181 items documented0 out of 30 items with examples
  • Size
  • Source code size: 522.85 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.58 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • fkaa

flu

flu is a framework for working with Lua 5.1 in the Rust programming language. It's meant to provide quasi-safe abstractions over core Lua concepts – but also unsafe access to the Lua stack.

What does it look like?

To interface with Lua through flu, you must first create a flu::LuaContext.You can do this by either wrapping around an existing *mut lua_State, or by using flu::LuaContext::new() to initialize a new one underneath.

let cxt = flu::LuaContext::new();
// or
let wrapped_cxt = flu::LuaContext::from_state(lua_state);

Abstractions

TODO

The stack

Modifying the stack is easy. flu::LuaContext has a function called push, which has the following definition:

pub fn push<T>(&self, val: T)
               where T: Push {
    val.push(self);
}

Essentially what this means is that everything that implements the Push trait can be pushed onto the stack. By default Push is implemented for the following types:

  • nil (a unit struct)
  • bool
  • i8, i16, i32
  • f32, f64
  • &str, String
  • Option<T: Push>
  • (A, B, ...) where A: Push, B: Push, ...

This also goes the other way when reading from the stack. flu provides another trait called Read which allows for types that implement it to be read back to Rust (Read is also implemented for the types mentioned earlier).

flu::LuaContext has 2 methods for reading values back from the stack – read and pop. read will return the value from the stack, but not remove it, whereas pop will. A simple example of pushing a value to the stack then reading it back might look like this:

let cxt = flu::LuaContext::new();

cxt.push("hello world!");
let val = cxt.pop::<&str>();

assert_eq!(val, "hello world!");

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.