diff --git a/src/runner/instance.rs b/src/runner/instance.rs index 4f34520..cb93481 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -1,6 +1,6 @@ use std::collections::{hash_map::Entry,HashMap}; -use mlua::{IntoLua,IntoLuaMulti}; +use mlua::{FromLuaMulti,IntoLua,IntoLuaMulti}; use rbx_types::Ref; use rbx_dom_weak::{InstanceBuilder,WeakDom}; @@ -320,15 +320,28 @@ impl mlua::UserData for Instance{ } } -fn place_id(lua:&mlua::Lua,tuple:mlua::MultiValue)->mlua::Result{ - 0.into_lua_multi(lua) +fn get_service(lua:&mlua::Lua,tuple:mlua::MultiValue)->mlua::Result{ + let (_game,service):(Instance,mlua::String)=FromLuaMulti::from_lua_multi(tuple,lua)?; + dom_mut(lua,|dom|{ + match &*service.to_str()?{ + "Lighting"=>{ + let referent=find_first_child_of_class(dom,dom.root(),"Lighting") + .map(|instance|instance.referent()) + .unwrap_or_else(|| + dom.insert(dom.root_ref(),InstanceBuilder::new("Lighting")) + ); + Instance::new(referent).into_lua_multi(lua) + }, + other=>Err::(mlua::Error::runtime(format!("Service '{other}' not supported"))), + } + }) } type FPointer=fn(&mlua::Lua,mlua::MultiValue)->mlua::Result; /// A double hash map of function pointers. /// The class tree is walked by the Instance.__index metamethod to find available class methods. static CLASS_FUNCTION_DATABASE:phf::Map<&str,phf::Map<&str,FPointer>>=phf::phf_map!{ "DataModel"=>phf::phf_map!{ - "GetService"=>place_id as FPointer, + "GetService"=>get_service as FPointer, } };