rlua-table-derive 0.1.0

This crate provides a procedural macro to turn lua tables into rust types via rlua
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 6.07 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 291.46 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • zwparchman/rlua-table-derive
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • zwparchman

rlua-table-derive

This crate provides a custom derive for a FromLuaTable trait

To derive just add FromLuaTable to the derive list for a struct. Default must be implemented for a type to use this macro.

An example usage can be found in the examples directory. I have copied it here for convenience:

#[macro_use] extern crate rlua_table_derive;
extern crate rlua;


#[derive(Default, Debug, Clone, FromLuaTable)]
pub struct Thing{
    x: f32,
    y: f32,

    name: String,
}

trait FromLuaTable {
    fn from_lua_table(table: &rlua::Table) -> Self;
}

const LUA_STRING: &str = "
thing = {
    x=2,
    name='john',
}
";

fn main() {
    let lua = rlua::Lua::new();
    lua.eval::<()>(LUA_STRING, Some("baked in")).unwrap();

    let default = Thing::default();

    let table = lua.globals().get("thing").unwrap();
    let from_lua = Thing::from_lua_table(&table);

    print!("Default: {:?}\n", default);
    print!("From lua: {:?}\n", from_lua);
}