From bd38c6f1e485728024f09cdb805b4aefd6c5021d Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 17 Oct 2024 11:33:20 -0700 Subject: [PATCH] runservice --- src/runner/instance.rs | 14 ++++++++++---- src/runner/runner.rs | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/runner/instance.rs b/src/runner/instance.rs index d055567..62e52f3 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -377,12 +377,13 @@ static CLASS_FUNCTION_DATABASE:CFD=phf::phf_map!{ "GetService"=>cf!(|lua,_this,service:mlua::String|{ dom_mut(lua,|dom|{ //dom.root_ref()==this.referent ? - match &*service.to_str()?{ - "Lighting"=>{ - let referent=find_first_child_of_class(dom,dom.root(),"Lighting") + let service=&*service.to_str()?; + match service{ + "Lighting"|"RunService"=>{ + let referent=find_first_child_of_class(dom,dom.root(),service) .map(|instance|instance.referent()) .unwrap_or_else(|| - dom.insert(dom.root_ref(),InstanceBuilder::new("Lighting")) + dom.insert(dom.root_ref(),InstanceBuilder::new(service)) ); Ok(Instance::new(referent)) }, @@ -504,6 +505,11 @@ type LUD=phf::Map<&'static str,// Class name > >; static LAZY_USER_DATA:LUD=phf::phf_map!{ + "RunService"=>phf::phf_map!{ + "RenderStepped"=>|lua|{ + lua.create_any_userdata(super::script_signal::ScriptSignal::new()) + }, + }, }; #[derive(Default)] pub struct InstanceValueStore{ diff --git a/src/runner/runner.rs b/src/runner/runner.rs index 39fa25a..debd1e1 100644 --- a/src/runner/runner.rs +++ b/src/runner/runner.rs @@ -120,4 +120,23 @@ impl Runnable<'_>{ } Ok(()) } + #[cfg(feature="run-service")] + pub fn run_service_step(&self)->Result<(),mlua::Error>{ + let render_stepped=super::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"))?; + super::instance::instance_value_store_mut(&self.lua,|instance_value_store|{ + //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).ok_or_else(||mlua::Error::runtime("RunService InstanceValues missing"))?; + let render_stepped=instance_values.get_or_create_value(&self.lua,"RenderStepped")?; + //let stepped=instance_values.get_or_create_value(&self.lua,"Stepped")?; + //let heartbeat=instance_values.get_or_create_value(&self.lua,"Heartbeat")?; + Ok(render_stepped) + }) + })?; + if let Some(render_stepped)=render_stepped{ + let signal:&super::script_signal::ScriptSignal=&*render_stepped.borrow()?; + signal.fire(mlua::MultiValue::new()); + } + Ok(()) + } }