diff --git a/lib/roblox_emulator/src/runner/instance/instance.rs b/lib/roblox_emulator/src/runner/instance/instance.rs index 14a6e7b0..c2c4a16e 100644 --- a/lib/roblox_emulator/src/runner/instance/instance.rs +++ b/lib/roblox_emulator/src/runner/instance/instance.rs @@ -377,25 +377,27 @@ type CFD=phf::Map<&'static str,// Class name ClassFunctionPointer > >; +const GET_SERVICE:ClassFunctionPointer=cf!(|lua,_this,service:mlua::String|{ + dom_mut(lua,|dom|{ + //dom.root_ref()==this.referent ? + 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(service)) + ); + Ok(Instance::new_unchecked(referent)) + }, + other=>Err::(mlua::Error::runtime(format!("Service '{other}' not supported"))), + } + }) +}); static CLASS_FUNCTION_DATABASE:CFD=phf::phf_map!{ "DataModel"=>phf::phf_map!{ - "GetService"=>cf!(|lua,_this,service:mlua::String|{ - dom_mut(lua,|dom|{ - //dom.root_ref()==this.referent ? - 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(service)) - ); - Ok(Instance::new_unchecked(referent)) - }, - other=>Err::(mlua::Error::runtime(format!("Service '{other}' not supported"))), - } - }) - }), + "service"=>GET_SERVICE, + "GetService"=>GET_SERVICE, }, "Terrain"=>phf::phf_map!{ "FillBlock"=>cf!(|_lua,_,_:(crate::runner::cframe::CFrame,Vector3,crate::runner::r#enum::Enum)|mlua::Result::Ok(()))