diff --git a/src/runner/instance.rs b/src/runner/instance.rs index 3489a3f..a54f826 100644 --- a/src/runner/instance.rs +++ b/src/runner/instance.rs @@ -4,6 +4,26 @@ use rbx_dom_weak::{InstanceBuilder,WeakDom}; use super::vector3::Vector3; +pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table<'_>)->Result<(),mlua::Error>{ + let instance_table=lua.create_table()?; + + //Instance.new + instance_table.raw_set("new", + lua.create_function(|lua,(class_name,parent):(mlua::String,Instance)|{ + let class_name_str=class_name.to_str()?; + dom_mut(lua,|dom|{ + //TODO: Nil instances, accept optional parent:Option + //let parent_ref=parent.map_or(NIL_INSTANCES,|instance|instance.referent); + Ok(Instance::new(dom.insert(parent.referent,InstanceBuilder::new(class_name_str)))) + }) + })? + )?; + + globals.set("Instance",instance_table)?; + + Ok(()) +} + // LMAO look at this function! fn dom_mut(lua:&mlua::Lua,mut f:impl FnMut(&mut WeakDom)->mlua::Result)->mlua::Result{ let mut dom=lua.app_data_mut::<&'static mut WeakDom>().ok_or(mlua::Error::runtime("DataModel missing"))?; diff --git a/src/runner/runner.rs b/src/runner/runner.rs index a6935cb..b603aa0 100644 --- a/src/runner/runner.rs +++ b/src/runner/runner.rs @@ -33,6 +33,7 @@ fn init(lua:&mlua::Lua)->mlua::Result<()>{ super::color3::set_globals(lua,&globals)?; super::vector3::set_globals(lua,&globals)?; super::cframe::set_globals(lua,&globals)?; + super::instance::set_globals(lua,&globals)?; Ok(()) }