diff --git a/src/runner/enum.rs b/src/runner/enum.rs index 29d500b..0b6bd47 100644 --- a/src/runner/enum.rs +++ b/src/runner/enum.rs @@ -2,7 +2,9 @@ use mlua::IntoLua; #[derive(Clone,Copy)] pub struct Enum(u32); +#[derive(Clone,Copy)] pub struct EnumItems; +#[derive(Clone,Copy)] pub struct EnumItem<'a>{ ed:&'a rbx_reflection::EnumDescriptor<'a>, } diff --git a/src/runner/instance.rs b/src/runner/instance.rs index cb93481..51308d5 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -10,6 +10,8 @@ pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{ //class functions store lua.set_app_data(ClassFunctions::default()); + lua.register_userdata_type(::register)?; + let instance_table=lua.create_table()?; //Instance.new @@ -222,10 +224,17 @@ impl mlua::UserData for Instance{ Ok(()) }) ); + methods.add_meta_function(mlua::MetaMethod::ToString,|lua,this:Instance|{ + dom_mut(lua,|dom|{ + let instance=this.get(dom)?; + Ok(instance.name.clone()) + }) + }); methods.add_meta_function(mlua::MetaMethod::Index,|lua,(this,index):(Instance,mlua::String)|{ let index_str=&*index.to_str()?; dom_mut(lua,|dom|{ let instance=this.get(dom)?; + //println!("__index t={} i={index:?}",instance.name); let db=rbx_reflection_database::get(); let class=db.classes.get(instance.class.as_str()).ok_or(mlua::Error::runtime("Class missing"))?; //Find existing property @@ -233,9 +242,13 @@ impl mlua::UserData for Instance{ //Find default value .or_else(||db.find_default_property(class,index_str)) { + Some(&rbx_types::Variant::Int32(val))=>return Ok(val.into_lua(lua)), + Some(&rbx_types::Variant::Int64(val))=>return Ok(val.into_lua(lua)), + Some(&rbx_types::Variant::Float32(val))=>return Ok(val.into_lua(lua)), + Some(&rbx_types::Variant::Float64(val))=>return Ok(val.into_lua(lua)), Some(&rbx_types::Variant::CFrame(cf))=>return Ok(Into::::into(cf).into_lua(lua)), Some(&rbx_types::Variant::Vector3(v))=>return Ok(Into::::into(v).into_lua(lua)), - _=>(), + other=>println!("instance.properties.get(i)={other:?}"), } //find a function with a matching name if let Some(function)=class_functions_mut(lua,|cf|{ diff --git a/src/runner/macros.rs b/src/runner/macros.rs index 33f78bc..180c020 100644 --- a/src/runner/macros.rs +++ b/src/runner/macros.rs @@ -3,7 +3,7 @@ macro_rules! type_from_lua_userdata{ impl mlua::FromLua for $asd{ fn from_lua(value:mlua::Value,_lua:&mlua::Lua)->Result{ match value{ - mlua::Value::UserData(ud)=>ud.take(), + mlua::Value::UserData(ud)=>Ok(*ud.borrow::()?), other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($asd),other))), } } @@ -12,10 +12,10 @@ macro_rules! type_from_lua_userdata{ } macro_rules! type_from_lua_userdata_lua_lifetime{ ($asd:ident)=>{ - impl mlua::FromLua for $asd<'_>{ + impl mlua::FromLua for $asd<'static>{ fn from_lua(value:mlua::Value,_lua:&mlua::Lua)->Result{ match value{ - mlua::Value::UserData(ud)=>ud.take(), + mlua::Value::UserData(ud)=>Ok(*ud.borrow::()?), other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($asd),other))), } }