fixed
This commit is contained in:
parent
0eff07d22d
commit
248f8d5b56
@ -2,7 +2,9 @@ use mlua::IntoLua;
|
|||||||
|
|
||||||
#[derive(Clone,Copy)]
|
#[derive(Clone,Copy)]
|
||||||
pub struct Enum(u32);
|
pub struct Enum(u32);
|
||||||
|
#[derive(Clone,Copy)]
|
||||||
pub struct EnumItems;
|
pub struct EnumItems;
|
||||||
|
#[derive(Clone,Copy)]
|
||||||
pub struct EnumItem<'a>{
|
pub struct EnumItem<'a>{
|
||||||
ed:&'a rbx_reflection::EnumDescriptor<'a>,
|
ed:&'a rbx_reflection::EnumDescriptor<'a>,
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
|||||||
//class functions store
|
//class functions store
|
||||||
lua.set_app_data(ClassFunctions::default());
|
lua.set_app_data(ClassFunctions::default());
|
||||||
|
|
||||||
|
lua.register_userdata_type(<Instance as mlua::UserData>::register)?;
|
||||||
|
|
||||||
let instance_table=lua.create_table()?;
|
let instance_table=lua.create_table()?;
|
||||||
|
|
||||||
//Instance.new
|
//Instance.new
|
||||||
@ -222,10 +224,17 @@ impl mlua::UserData for Instance{
|
|||||||
Ok(())
|
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)|{
|
methods.add_meta_function(mlua::MetaMethod::Index,|lua,(this,index):(Instance,mlua::String)|{
|
||||||
let index_str=&*index.to_str()?;
|
let index_str=&*index.to_str()?;
|
||||||
dom_mut(lua,|dom|{
|
dom_mut(lua,|dom|{
|
||||||
let instance=this.get(dom)?;
|
let instance=this.get(dom)?;
|
||||||
|
//println!("__index t={} i={index:?}",instance.name);
|
||||||
let db=rbx_reflection_database::get();
|
let db=rbx_reflection_database::get();
|
||||||
let class=db.classes.get(instance.class.as_str()).ok_or(mlua::Error::runtime("Class missing"))?;
|
let class=db.classes.get(instance.class.as_str()).ok_or(mlua::Error::runtime("Class missing"))?;
|
||||||
//Find existing property
|
//Find existing property
|
||||||
@ -233,9 +242,13 @@ impl mlua::UserData for Instance{
|
|||||||
//Find default value
|
//Find default value
|
||||||
.or_else(||db.find_default_property(class,index_str))
|
.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::<super::cframe::CFrame>::into(cf).into_lua(lua)),
|
Some(&rbx_types::Variant::CFrame(cf))=>return Ok(Into::<super::cframe::CFrame>::into(cf).into_lua(lua)),
|
||||||
Some(&rbx_types::Variant::Vector3(v))=>return Ok(Into::<super::vector3::Vector3>::into(v).into_lua(lua)),
|
Some(&rbx_types::Variant::Vector3(v))=>return Ok(Into::<super::vector3::Vector3>::into(v).into_lua(lua)),
|
||||||
_=>(),
|
other=>println!("instance.properties.get(i)={other:?}"),
|
||||||
}
|
}
|
||||||
//find a function with a matching name
|
//find a function with a matching name
|
||||||
if let Some(function)=class_functions_mut(lua,|cf|{
|
if let Some(function)=class_functions_mut(lua,|cf|{
|
||||||
|
@ -3,7 +3,7 @@ macro_rules! type_from_lua_userdata{
|
|||||||
impl mlua::FromLua for $asd{
|
impl mlua::FromLua for $asd{
|
||||||
fn from_lua(value:mlua::Value,_lua:&mlua::Lua)->Result<Self,mlua::Error>{
|
fn from_lua(value:mlua::Value,_lua:&mlua::Lua)->Result<Self,mlua::Error>{
|
||||||
match value{
|
match value{
|
||||||
mlua::Value::UserData(ud)=>ud.take(),
|
mlua::Value::UserData(ud)=>Ok(*ud.borrow::<Self>()?),
|
||||||
other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($asd),other))),
|
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{
|
macro_rules! type_from_lua_userdata_lua_lifetime{
|
||||||
($asd:ident)=>{
|
($asd:ident)=>{
|
||||||
impl mlua::FromLua for $asd<'_>{
|
impl mlua::FromLua for $asd<'static>{
|
||||||
fn from_lua(value:mlua::Value,_lua:&mlua::Lua)->Result<Self,mlua::Error>{
|
fn from_lua(value:mlua::Value,_lua:&mlua::Lua)->Result<Self,mlua::Error>{
|
||||||
match value{
|
match value{
|
||||||
mlua::Value::UserData(ud)=>ud.take(),
|
mlua::Value::UserData(ud)=>Ok(*ud.borrow::<Self>()?),
|
||||||
other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($asd),other))),
|
other=>Err(mlua::Error::runtime(format!("Expected {} got {:?}",stringify!($asd),other))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user