fixed
This commit is contained in:
parent
0eff07d22d
commit
248f8d5b56
@ -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>,
|
||||
}
|
||||
|
@ -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(<Instance as mlua::UserData>::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::<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)),
|
||||
_=>(),
|
||||
other=>println!("instance.properties.get(i)={other:?}"),
|
||||
}
|
||||
//find a function with a matching name
|
||||
if let Some(function)=class_functions_mut(lua,|cf|{
|
||||
|
@ -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<Self,mlua::Error>{
|
||||
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))),
|
||||
}
|
||||
}
|
||||
@ -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<Self,mlua::Error>{
|
||||
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))),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user