roblox_emulator: rename Instance constructors
This commit is contained in:
@@ -55,7 +55,7 @@ impl Context{
|
||||
.with_child(script)
|
||||
);
|
||||
let context=Self::from_model(dom);
|
||||
(context,crate::runner::instance::Instance::new(script_ref))
|
||||
(context,crate::runner::instance::Instance::new_unchecked(script_ref))
|
||||
}
|
||||
/// Creates an iterator over all items of a particular class.
|
||||
pub fn superclass_iter<'a>(&'a self,superclass:&'a str)->impl Iterator<Item=Ref>+'a{
|
||||
@@ -69,7 +69,7 @@ impl Context{
|
||||
})
|
||||
}
|
||||
pub fn scripts(&self)->Vec<crate::runner::instance::Instance>{
|
||||
self.superclass_iter("LuaSourceContainer").map(crate::runner::instance::Instance::new).collect()
|
||||
self.superclass_iter("LuaSourceContainer").map(crate::runner::instance::Instance::new_unchecked).collect()
|
||||
}
|
||||
|
||||
pub fn from_model(mut dom:WeakDom)->Context{
|
||||
|
||||
@@ -24,7 +24,7 @@ pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
||||
let class_name_str=&*class_name.to_str()?;
|
||||
let parent=parent.unwrap_or(Instance::nil());
|
||||
dom_mut(lua,|dom|{
|
||||
Ok(Instance::new(dom.insert(parent.referent,InstanceBuilder::new(class_name_str))))
|
||||
Ok(Instance::new_unchecked(dom.insert(parent.referent,InstanceBuilder::new(class_name_str))))
|
||||
})
|
||||
})?
|
||||
)?;
|
||||
@@ -95,10 +95,10 @@ pub struct Instance{
|
||||
referent:Ref,
|
||||
}
|
||||
impl Instance{
|
||||
pub const fn new(referent:Ref)->Self{
|
||||
pub const fn new_unchecked(referent:Ref)->Self{
|
||||
Self{referent}
|
||||
}
|
||||
pub fn maybe_nil(referent:Ref)->Option<Self>{
|
||||
pub fn new(referent:Ref)->Option<Self>{
|
||||
match referent=="ffffffffffffffffffffffffffffffff".parse().unwrap(){
|
||||
true=>None,
|
||||
false=>Some(Self{referent})
|
||||
@@ -124,7 +124,7 @@ impl mlua::UserData for Instance{
|
||||
fields.add_field_method_get("Parent",|lua,this|{
|
||||
dom_mut(lua,|dom|{
|
||||
let instance=this.get(dom)?;
|
||||
Ok(Instance::maybe_nil(instance.parent()))
|
||||
Ok(Instance::new(instance.parent()))
|
||||
})
|
||||
});
|
||||
fields.add_field_method_set("Parent",|lua,this,val:Option<Instance>|{
|
||||
@@ -163,7 +163,7 @@ impl mlua::UserData for Instance{
|
||||
.children()
|
||||
.iter()
|
||||
.copied()
|
||||
.map(Instance::new)
|
||||
.map(Instance::new_unchecked)
|
||||
.collect();
|
||||
Ok(children)
|
||||
})
|
||||
@@ -178,7 +178,7 @@ impl mlua::UserData for Instance{
|
||||
false=>find_first_child(dom,instance,name_str),
|
||||
}
|
||||
.map(|instance|
|
||||
Instance::new(instance.referent())
|
||||
Instance::new_unchecked(instance.referent())
|
||||
)
|
||||
)
|
||||
})
|
||||
@@ -194,7 +194,7 @@ impl mlua::UserData for Instance{
|
||||
false=>find_first_child_of_class(dom,this.get(dom)?,class_str),
|
||||
}
|
||||
.map(|instance|
|
||||
Instance::new(instance.referent())
|
||||
Instance::new_unchecked(instance.referent())
|
||||
)
|
||||
)
|
||||
})
|
||||
@@ -204,7 +204,7 @@ impl mlua::UserData for Instance{
|
||||
let children:Vec<_>=dom
|
||||
.descendants_of(this.referent)
|
||||
.map(|instance|
|
||||
Instance::new(instance.referent())
|
||||
Instance::new_unchecked(instance.referent())
|
||||
)
|
||||
.collect();
|
||||
Ok(children)
|
||||
@@ -253,7 +253,7 @@ impl mlua::UserData for Instance{
|
||||
Some(rbx_types::Variant::Int64(val))=>return val.into_lua(lua),
|
||||
Some(rbx_types::Variant::Float32(val))=>return val.into_lua(lua),
|
||||
Some(rbx_types::Variant::Float64(val))=>return val.into_lua(lua),
|
||||
Some(rbx_types::Variant::Ref(val))=>return Instance::new(val).into_lua(lua),
|
||||
Some(rbx_types::Variant::Ref(val))=>return Instance::new_unchecked(val).into_lua(lua),
|
||||
Some(rbx_types::Variant::CFrame(cf))=>return Into::<crate::runner::cframe::CFrame>::into(cf).into_lua(lua),
|
||||
Some(rbx_types::Variant::Vector3(v))=>return Into::<crate::runner::vector3::Vector3>::into(v).into_lua(lua),
|
||||
None=>(),
|
||||
@@ -282,7 +282,7 @@ impl mlua::UserData for Instance{
|
||||
}
|
||||
//find a child with a matching name
|
||||
find_first_child(dom,instance,index_str)
|
||||
.map(|instance|Instance::new(instance.referent()))
|
||||
.map(|instance|Instance::new_unchecked(instance.referent()))
|
||||
.into_lua(lua)
|
||||
})
|
||||
});
|
||||
@@ -385,7 +385,7 @@ static CLASS_FUNCTION_DATABASE:CFD=phf::phf_map!{
|
||||
.unwrap_or_else(||
|
||||
dom.insert(dom.root_ref(),InstanceBuilder::new(service))
|
||||
);
|
||||
Ok(Instance::new(referent))
|
||||
Ok(Instance::new_unchecked(referent))
|
||||
},
|
||||
other=>Err::<Instance,_>(mlua::Error::runtime(format!("Service '{other}' not supported"))),
|
||||
}
|
||||
|
||||
@@ -56,8 +56,8 @@ impl Runner{
|
||||
pub fn runnable_context<'a>(self,context:&'a mut Context)->Result<Runnable<'a>,Error>{
|
||||
{
|
||||
let globals=self.lua.globals();
|
||||
globals.set("game",super::instance::Instance::new(context.services.game)).map_err(Error::RustLua)?;
|
||||
globals.set("workspace",super::instance::Instance::new(context.services.workspace)).map_err(Error::RustLua)?;
|
||||
globals.set("game",super::instance::Instance::new_unchecked(context.services.game)).map_err(Error::RustLua)?;
|
||||
globals.set("workspace",super::instance::Instance::new_unchecked(context.services.workspace)).map_err(Error::RustLua)?;
|
||||
}
|
||||
//this makes set_app_data shut up about the lifetime
|
||||
self.lua.set_app_data::<crate::context::LuaAppData>(unsafe{core::mem::transmute(&mut context.dom)});
|
||||
|
||||
Reference in New Issue
Block a user