#[macro_export]
macro_rules! mlua_create_named_parameters {
($type_name:ident with $($field_name:ident : $field_type_name:ty, )*) => {
pub struct $type_name {
$(pub $field_name : $field_type_name,)*
}
impl $crate::TypeName for $type_name {
fn get_type_parts() -> std::borrow::Cow<'static, [$crate::NamePart]> {
let mut x = Vec::new();
$(
x.push($crate::NamePart::symbol(stringify!($field_name)));
x.push($crate::NamePart::symbol(" : "));
x.extend(<$field_type_name as $crate::TypeName>::get_type_parts().iter().map(std::borrow::ToOwned::to_owned));
x.push($crate::NamePart::symbol(" , "));
)*
x.remove(x.len() - 1);
std::convert::From::from(x)
}
}
impl<'lua> $crate::mlu::mlua::FromLuaMulti<'lua> for $type_name {
fn from_lua_multi(
mut values: $crate::mlu::mlua::MultiValue<'lua>,
lua: &'lua $crate::mlu::mlua::Lua,
) -> $crate::mlu::mlua::Result<Self> {
Ok(Self {
$($field_name: <_ as $crate::mlu::mlua::FromLua>::from_lua(
values
.pop_front()
.unwrap_or_else(|| $crate::mlu::mlua::Value::Nil),
lua,
)?,)*
})
}
}
};
}