rlua-table-derive

Crates.iorlua-table-derive
lib.rsrlua-table-derive
version0.1.0
sourcesrc
created_at2018-01-03 18:48:03.976679
updated_at2018-01-03 18:48:03.976679
descriptionThis crate provides a procedural macro to turn lua tables into rust types via rlua
homepage
repositoryhttps://github.com/zwparchman/rlua-table-derive
max_upload_size
id45409
size4,936
(zwparchman)

documentation

README

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);
}
Commit count: 5

cargo fmt