Expand description
This crate allows you to serialize and deserialize any type that implements
serde::Serialize
and serde::Deserialize
into/from rlua::Value
.
Implementation is similar to serde_json::Value
Example usage:
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate rlua;
extern crate rlua_serde;
fn main() {
#[derive(Serialize, Deserialize)]
struct Foo {
bar: u32,
baz: Vec<String>,
}
let lua = rlua::Lua::new();
lua.context(|lua| {
let foo = Foo {
bar: 42,
baz: vec![String::from("fizz"), String::from("buzz")],
};
let value = rlua_serde::to_value(lua, &foo).unwrap();
lua.globals().set("value", value).unwrap();
lua.load(
r#"
assert(value["bar"] == 42)
assert(value["baz"][2] == "buzz")
"#).exec().unwrap();
});
}