impl_fromlua_as_serde

Macro impl_fromlua_as_serde 

Source
macro_rules! impl_fromlua_as_serde {
    ($t:ty) => { ... };
    (owned $t:ty) => { ... };
}
Expand description

Helper macro to impl FromLua for serializable types easily

use serde::{Deserialize, Serialize};

#[derive(Debug, Default, Deserialize, Serialize)]
struct Config {
    name: String,
    path: String,
    timeout: u64,
    // ...
}

ezlua::impl_fromlua_as_serde!(Config);

let lua = Lua::with_open_libs();
lua.global().set_closure("set_config", |config: Config| {
    println!("{config:?}");
})?;
lua.do_string("set_config({name = 'test', path = '/', timeout = 0})", None)?;
// will print `Config { name: "test", path: "/", timeout: 0 }`