move instance into module to further break it down
This commit is contained in:
parent
557aad6ec4
commit
2d4a19dd0b
@ -4,7 +4,7 @@ use mlua::{FromLua,FromLuaMulti,IntoLua,IntoLuaMulti};
|
|||||||
use rbx_types::Ref;
|
use rbx_types::Ref;
|
||||||
use rbx_dom_weak::{InstanceBuilder,WeakDom};
|
use rbx_dom_weak::{InstanceBuilder,WeakDom};
|
||||||
|
|
||||||
use super::vector3::Vector3;
|
use crate::runner::vector3::Vector3;
|
||||||
|
|
||||||
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
||||||
//class functions store
|
//class functions store
|
||||||
@ -253,8 +253,8 @@ impl mlua::UserData for Instance{
|
|||||||
Some(rbx_types::Variant::Float32(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::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(val).into_lua(lua),
|
||||||
Some(rbx_types::Variant::CFrame(cf))=>return Into::<super::cframe::CFrame>::into(cf).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::<super::vector3::Vector3>::into(v).into_lua(lua),
|
Some(rbx_types::Variant::Vector3(v))=>return Into::<crate::runner::vector3::Vector3>::into(v).into_lua(lua),
|
||||||
None=>(),
|
None=>(),
|
||||||
other=>return Err(mlua::Error::runtime(format!("Instance.__index Unsupported property type instance={} index={index_str} value={other:?}",instance.name))),
|
other=>return Err(mlua::Error::runtime(format!("Instance.__index Unsupported property type instance={} index={index_str} value={other:?}",instance.name))),
|
||||||
}
|
}
|
||||||
@ -319,7 +319,7 @@ impl mlua::UserData for Instance{
|
|||||||
Ok(rbx_types::Enum::from_u32(*e.items.get(&*s.to_str()?).ok_or(mlua::Error::runtime("Invalid enum item"))?))
|
Ok(rbx_types::Enum::from_u32(*e.items.get(&*s.to_str()?).ok_or(mlua::Error::runtime("Invalid enum item"))?))
|
||||||
},
|
},
|
||||||
mlua::Value::UserData(any_user_data)=>{
|
mlua::Value::UserData(any_user_data)=>{
|
||||||
let e:super::r#enum::Enum=*any_user_data.borrow()?;
|
let e:crate::runner::r#enum::Enum=*any_user_data.borrow()?;
|
||||||
Ok(e.into())
|
Ok(e.into())
|
||||||
},
|
},
|
||||||
_=>Err(mlua::Error::runtime("Expected Enum")),
|
_=>Err(mlua::Error::runtime("Expected Enum")),
|
||||||
@ -327,7 +327,7 @@ impl mlua::UserData for Instance{
|
|||||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Enum(typed_value));
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Enum(typed_value));
|
||||||
},
|
},
|
||||||
rbx_reflection::DataType::Value(rbx_types::VariantType::Color3)=>{
|
rbx_reflection::DataType::Value(rbx_types::VariantType::Color3)=>{
|
||||||
let typed_value:super::color3::Color3=*value.as_userdata().ok_or(mlua::Error::runtime("Expected Color3"))?.borrow()?;
|
let typed_value:crate::runner::color3::Color3=*value.as_userdata().ok_or(mlua::Error::runtime("Expected Color3"))?.borrow()?;
|
||||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Color3(typed_value.into()));
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Color3(typed_value.into()));
|
||||||
},
|
},
|
||||||
rbx_reflection::DataType::Value(rbx_types::VariantType::Bool)=>{
|
rbx_reflection::DataType::Value(rbx_types::VariantType::Bool)=>{
|
||||||
@ -339,11 +339,11 @@ impl mlua::UserData for Instance{
|
|||||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::String(typed_value.to_owned()));
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::String(typed_value.to_owned()));
|
||||||
},
|
},
|
||||||
rbx_reflection::DataType::Value(rbx_types::VariantType::NumberSequence)=>{
|
rbx_reflection::DataType::Value(rbx_types::VariantType::NumberSequence)=>{
|
||||||
let typed_value:super::number_sequence::NumberSequence=*value.as_userdata().ok_or(mlua::Error::runtime("Expected NumberSequence"))?.borrow()?;
|
let typed_value:crate::runner::number_sequence::NumberSequence=*value.as_userdata().ok_or(mlua::Error::runtime("Expected NumberSequence"))?.borrow()?;
|
||||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::NumberSequence(typed_value.into()));
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::NumberSequence(typed_value.into()));
|
||||||
},
|
},
|
||||||
rbx_reflection::DataType::Value(rbx_types::VariantType::ColorSequence)=>{
|
rbx_reflection::DataType::Value(rbx_types::VariantType::ColorSequence)=>{
|
||||||
let typed_value:super::color_sequence::ColorSequence=*value.as_userdata().ok_or(mlua::Error::runtime("Expected ColorSequence"))?.borrow()?;
|
let typed_value:crate::runner::color_sequence::ColorSequence=*value.as_userdata().ok_or(mlua::Error::runtime("Expected ColorSequence"))?.borrow()?;
|
||||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::ColorSequence(typed_value.into()));
|
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::ColorSequence(typed_value.into()));
|
||||||
},
|
},
|
||||||
other=>return Err(mlua::Error::runtime(format!("Unimplemented property type: {other:?}"))),
|
other=>return Err(mlua::Error::runtime(format!("Unimplemented property type: {other:?}"))),
|
||||||
@ -393,7 +393,7 @@ static CLASS_FUNCTION_DATABASE:CFD=phf::phf_map!{
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
"Terrain"=>phf::phf_map!{
|
"Terrain"=>phf::phf_map!{
|
||||||
"FillBlock"=>cf!(|_lua,_,_:(super::cframe::CFrame,Vector3,super::r#enum::Enum)|mlua::Result::Ok(()))
|
"FillBlock"=>cf!(|_lua,_,_:(crate::runner::cframe::CFrame,Vector3,crate::runner::r#enum::Enum)|mlua::Result::Ok(()))
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -507,7 +507,7 @@ type LUD=phf::Map<&'static str,// Class name
|
|||||||
static LAZY_USER_DATA:LUD=phf::phf_map!{
|
static LAZY_USER_DATA:LUD=phf::phf_map!{
|
||||||
"RunService"=>phf::phf_map!{
|
"RunService"=>phf::phf_map!{
|
||||||
"RenderStepped"=>|lua|{
|
"RenderStepped"=>|lua|{
|
||||||
lua.create_any_userdata(super::script_signal::ScriptSignal::new())
|
lua.create_any_userdata(crate::runner::script_signal::ScriptSignal::new())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
2
src/runner/instance/mod.rs
Normal file
2
src/runner/instance/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod instance;
|
||||||
|
pub use instance::Instance;
|
@ -37,7 +37,7 @@ fn init(lua:&mlua::Lua)->mlua::Result<()>{
|
|||||||
super::color3::set_globals(lua,&globals)?;
|
super::color3::set_globals(lua,&globals)?;
|
||||||
super::vector3::set_globals(lua,&globals)?;
|
super::vector3::set_globals(lua,&globals)?;
|
||||||
super::cframe::set_globals(lua,&globals)?;
|
super::cframe::set_globals(lua,&globals)?;
|
||||||
super::instance::set_globals(lua,&globals)?;
|
super::instance::instance::set_globals(lua,&globals)?;
|
||||||
super::number_sequence::set_globals(lua,&globals)?;
|
super::number_sequence::set_globals(lua,&globals)?;
|
||||||
super::color_sequence::set_globals(lua,&globals)?;
|
super::color_sequence::set_globals(lua,&globals)?;
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ impl Runnable<'_>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn run_script(&self,script:super::instance::Instance)->Result<(),Error>{
|
pub fn run_script(&self,script:super::instance::Instance)->Result<(),Error>{
|
||||||
let (name,source)=super::instance::get_name_source(&self.lua,script).map_err(Error::RustLua)?;
|
let (name,source)=super::instance::instance::get_name_source(&self.lua,script).map_err(Error::RustLua)?;
|
||||||
self.lua.globals().raw_set("script",script).map_err(Error::RustLua)?;
|
self.lua.globals().raw_set("script",script).map_err(Error::RustLua)?;
|
||||||
let f=self.lua.load(source.as_str())
|
let f=self.lua.load(source.as_str())
|
||||||
.set_name(name).into_function().map_err(Error::RustLua)?;
|
.set_name(name).into_function().map_err(Error::RustLua)?;
|
||||||
@ -124,9 +124,9 @@ impl Runnable<'_>{
|
|||||||
}
|
}
|
||||||
#[cfg(feature="run-service")]
|
#[cfg(feature="run-service")]
|
||||||
pub fn run_service_step(&self)->Result<(),mlua::Error>{
|
pub fn run_service_step(&self)->Result<(),mlua::Error>{
|
||||||
let render_stepped=super::instance::dom_mut(&self.lua,|dom|{
|
let render_stepped=super::instance::instance::dom_mut(&self.lua,|dom|{
|
||||||
let run_service=super::instance::find_first_child_of_class(dom,dom.root(),"RunService").ok_or_else(||mlua::Error::runtime("RunService missing"))?;
|
let run_service=super::instance::instance::find_first_child_of_class(dom,dom.root(),"RunService").ok_or_else(||mlua::Error::runtime("RunService missing"))?;
|
||||||
super::instance::instance_value_store_mut(&self.lua,|instance_value_store|{
|
super::instance::instance::instance_value_store_mut(&self.lua,|instance_value_store|{
|
||||||
//unwrap because I trust my find_first_child_of_class function to
|
//unwrap because I trust my find_first_child_of_class function to
|
||||||
let mut instance_values=instance_value_store.get_or_create_instance_values(run_service).unwrap();
|
let mut instance_values=instance_value_store.get_or_create_instance_values(run_service).unwrap();
|
||||||
let render_stepped=instance_values.get_or_create_value(&self.lua,"RenderStepped")?;
|
let render_stepped=instance_values.get_or_create_value(&self.lua,"RenderStepped")?;
|
||||||
|
Loading…
Reference in New Issue
Block a user