Crates.io | rlua-table-derive |
lib.rs | rlua-table-derive |
version | 0.1.0 |
source | src |
created_at | 2018-01-03 18:48:03.976679 |
updated_at | 2018-01-03 18:48:03.976679 |
description | This crate provides a procedural macro to turn lua tables into rust types via rlua |
homepage | |
repository | https://github.com/zwparchman/rlua-table-derive |
max_upload_size | |
id | 45409 |
size | 4,936 |
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);
}