diff --git a/src/runner/instance.rs b/src/runner/instance.rs index 720b7a3..b48db73 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -1,5 +1,6 @@ +use mlua::IntoLua; use rbx_types::Ref; -use rbx_dom_weak::WeakDom; +use rbx_dom_weak::{InstanceBuilder,WeakDom}; use super::vector3::Vector3; @@ -186,13 +187,27 @@ class!(DataModel); class_composition!(DataModel,(Instance,DataModel)); impl DataModel{ fn composition_add_fields<'lua,T:Referent,F:mlua::UserDataFields<'lua,T>>(fields:&mut F){ + fields.add_field_method_get("PlaceId",|lua,this|{ + Ok(mlua::Value::Integer(0)) + }); } fn composition_add_methods<'lua,T,M:mlua::UserDataMethods<'lua,T>>(methods:&mut M){ methods.add_method("GetService",|lua,this,service:String| dom(lua,|dom|{ match service.as_str(){ - //"Lighting"=>Ok(Lighting::new()), - other=>Err::<(),_>(mlua::Error::runtime("Service '{other}' not supported")), + "Lighting"=>{ + let referent=dom.root() + .children() + .iter() + .find(|&&c| + dom.get_by_ref(c).is_some_and(|c|c.class=="Lighting") + ).map(|r|*r) + .unwrap_or_else(|| + dom.insert(dom.root_ref(),InstanceBuilder::new("Lighting")) + ); + Lighting::new(referent).into_lua(lua) + }, + other=>Err::(mlua::Error::runtime(format!("Service '{other}' not supported"))), } }) );