roblox_emulator: implement :service alias for GetService
This commit is contained in:
@ -377,25 +377,27 @@ type CFD=phf::Map<&'static str,// Class name
|
|||||||
ClassFunctionPointer
|
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::<Instance,_>(mlua::Error::runtime(format!("Service '{other}' not supported"))),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
static CLASS_FUNCTION_DATABASE:CFD=phf::phf_map!{
|
static CLASS_FUNCTION_DATABASE:CFD=phf::phf_map!{
|
||||||
"DataModel"=>phf::phf_map!{
|
"DataModel"=>phf::phf_map!{
|
||||||
"GetService"=>cf!(|lua,_this,service:mlua::String|{
|
"service"=>GET_SERVICE,
|
||||||
dom_mut(lua,|dom|{
|
"GetService"=>GET_SERVICE,
|
||||||
//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::<Instance,_>(mlua::Error::runtime(format!("Service '{other}' not supported"))),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
"Terrain"=>phf::phf_map!{
|
"Terrain"=>phf::phf_map!{
|
||||||
"FillBlock"=>cf!(|_lua,_,_:(crate::runner::cframe::CFrame,Vector3,crate::runner::r#enum::Enum)|mlua::Result::Ok(()))
|
"FillBlock"=>cf!(|_lua,_,_:(crate::runner::cframe::CFrame,Vector3,crate::runner::r#enum::Enum)|mlua::Result::Ok(()))
|
||||||
|
Reference in New Issue
Block a user