from_lua macro
This commit is contained in:
parent
9d219004f4
commit
5a1df16bd9
@ -76,11 +76,5 @@ impl mlua::UserData for CFrame{
|
||||
);
|
||||
}
|
||||
}
|
||||
impl<'lua> mlua::FromLua<'lua> for CFrame{
|
||||
fn from_lua(value:mlua::prelude::LuaValue<'lua>,_lua:&'lua mlua::prelude::Lua)->mlua::prelude::LuaResult<Self>{
|
||||
match value{
|
||||
mlua::Value::UserData(ud)=>ud.take()?,
|
||||
other=>Err(mlua::Error::runtime(format!("Expected CFrame got {:?}",other))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type_from_lua_userdata!(CFrame);
|
||||
|
@ -40,11 +40,4 @@ impl mlua::UserData for Color3{
|
||||
fn add_methods<'lua,M:mlua::UserDataMethods<'lua,Self>>(methods:&mut M){
|
||||
}
|
||||
}
|
||||
impl<'lua> mlua::FromLua<'lua> for Color3{
|
||||
fn from_lua(value:mlua::prelude::LuaValue<'lua>,_lua:&'lua mlua::prelude::Lua)->mlua::prelude::LuaResult<Self>{
|
||||
match value{
|
||||
mlua::Value::UserData(ud)=>ud.take()?,
|
||||
other=>Err(mlua::Error::runtime(format!("Expected Color3 got {:?}",other))),
|
||||
}
|
||||
}
|
||||
}
|
||||
type_from_lua_userdata!(Color3);
|
||||
|
@ -39,14 +39,7 @@ impl mlua::UserData for EnumItem{
|
||||
});
|
||||
}
|
||||
}
|
||||
impl<'lua> mlua::FromLua<'lua> for EnumItem{
|
||||
fn from_lua(value:mlua::prelude::LuaValue<'lua>,_lua:&'lua mlua::prelude::Lua)->mlua::prelude::LuaResult<Self>{
|
||||
match value{
|
||||
mlua::Value::UserData(ud)=>ud.take()?,
|
||||
other=>Err(mlua::Error::runtime(format!("Expected Enum got {:?}",other))),
|
||||
}
|
||||
}
|
||||
}
|
||||
type_from_lua_userdata!(EnumItem);
|
||||
|
||||
impl mlua::UserData for EnumItems{
|
||||
fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(_fields:&mut F){
|
||||
@ -61,14 +54,7 @@ impl mlua::UserData for EnumItems{
|
||||
});
|
||||
}
|
||||
}
|
||||
impl<'lua> mlua::FromLua<'lua> for EnumItems{
|
||||
fn from_lua(value:mlua::prelude::LuaValue<'lua>,_lua:&'lua mlua::prelude::Lua)->mlua::prelude::LuaResult<Self>{
|
||||
match value{
|
||||
mlua::Value::UserData(ud)=>ud.take()?,
|
||||
other=>Err(mlua::Error::runtime(format!("Expected Enum got {:?}",other))),
|
||||
}
|
||||
}
|
||||
}
|
||||
type_from_lua_userdata!(EnumItems);
|
||||
|
||||
impl mlua::UserData for Enum{
|
||||
fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(_fields:&mut F){
|
||||
@ -76,11 +62,4 @@ impl mlua::UserData for Enum{
|
||||
fn add_methods<'lua,M:mlua::UserDataMethods<'lua,Self>>(_methods:&mut M){
|
||||
}
|
||||
}
|
||||
impl<'lua> mlua::FromLua<'lua> for Enum{
|
||||
fn from_lua(value:mlua::prelude::LuaValue<'lua>,_lua:&'lua mlua::prelude::Lua)->mlua::prelude::LuaResult<Self>{
|
||||
match value{
|
||||
mlua::Value::UserData(ud)=>ud.take()?,
|
||||
other=>Err(mlua::Error::runtime(format!("Expected Enum got {:?}",other))),
|
||||
}
|
||||
}
|
||||
}
|
||||
type_from_lua_userdata!(Enum);
|
||||
|
@ -54,14 +54,7 @@ macro_rules! class{
|
||||
self.referent
|
||||
}
|
||||
}
|
||||
impl<'lua> mlua::FromLua<'lua> for $class{
|
||||
fn from_lua(value:mlua::Value<'lua>,_lua:&'lua mlua::Lua)->mlua::Result<Self>{
|
||||
match value{
|
||||
mlua::Value::UserData(ud)=>ud.take(),
|
||||
other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($class),other))),
|
||||
}
|
||||
}
|
||||
}
|
||||
type_from_lua_userdata!($class);
|
||||
};
|
||||
}
|
||||
macro_rules! class_composition{
|
||||
|
12
src/runner/macros.rs
Normal file
12
src/runner/macros.rs
Normal file
@ -0,0 +1,12 @@
|
||||
macro_rules! type_from_lua_userdata{
|
||||
($asd:ident)=>{
|
||||
impl<'lua> mlua::FromLua<'lua> for $asd{
|
||||
fn from_lua(value:mlua::Value<'lua>,_lua:&'lua mlua::Lua)->Result<Self,mlua::Error>{
|
||||
match value{
|
||||
mlua::Value::UserData(ud)=>ud.take(),
|
||||
other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($asd),other))),
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
mod runner;
|
||||
|
||||
mod r#enum;
|
||||
|
@ -73,11 +73,4 @@ impl mlua::UserData for Vector3{
|
||||
}
|
||||
}
|
||||
|
||||
impl<'lua> mlua::FromLua<'lua> for Vector3{
|
||||
fn from_lua(value:mlua::prelude::LuaValue<'lua>,_lua:&'lua mlua::prelude::Lua)->mlua::prelude::LuaResult<Self>{
|
||||
match value{
|
||||
mlua::Value::UserData(ud)=>ud.take(),
|
||||
other=>Err(mlua::Error::runtime(format!("Expected Vector3 got {:?}",other))),
|
||||
}
|
||||
}
|
||||
}
|
||||
type_from_lua_userdata!(Vector3);
|
||||
|
Loading…
Reference in New Issue
Block a user