2024-10-04 01:53:17 +00:00
|
|
|
macro_rules! type_from_lua_userdata{
|
|
|
|
($asd:ident)=>{
|
2024-10-05 19:35:38 +00:00
|
|
|
impl mlua::FromLua for $asd{
|
|
|
|
fn from_lua(value:mlua::Value,_lua:&mlua::Lua)->Result<Self,mlua::Error>{
|
2024-10-04 01:53:17 +00:00
|
|
|
match value{
|
2024-10-05 19:35:38 +00:00
|
|
|
mlua::Value::UserData(ud)=>Ok(*ud.borrow::<Self>()?),
|
2024-10-04 01:53:17 +00:00
|
|
|
other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($asd),other))),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2024-10-05 00:33:59 +00:00
|
|
|
macro_rules! type_from_lua_userdata_lua_lifetime{
|
|
|
|
($asd:ident)=>{
|
2024-10-05 19:35:38 +00:00
|
|
|
impl mlua::FromLua for $asd<'static>{
|
|
|
|
fn from_lua(value:mlua::Value,_lua:&mlua::Lua)->Result<Self,mlua::Error>{
|
2024-10-05 00:33:59 +00:00
|
|
|
match value{
|
2024-10-05 19:35:38 +00:00
|
|
|
mlua::Value::UserData(ud)=>Ok(*ud.borrow::<Self>()?),
|
2024-10-05 00:33:59 +00:00
|
|
|
other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($asd),other))),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|