Instance globals
This commit is contained in:
parent
ed3f9f9b30
commit
b457da64a1
@ -4,6 +4,26 @@ use rbx_dom_weak::{InstanceBuilder,WeakDom};
|
|||||||
|
|
||||||
use super::vector3::Vector3;
|
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<Instance>
|
||||||
|
//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!
|
// LMAO look at this function!
|
||||||
fn dom_mut<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut WeakDom)->mlua::Result<T>)->mlua::Result<T>{
|
fn dom_mut<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut WeakDom)->mlua::Result<T>)->mlua::Result<T>{
|
||||||
let mut dom=lua.app_data_mut::<&'static mut WeakDom>().ok_or(mlua::Error::runtime("DataModel missing"))?;
|
let mut dom=lua.app_data_mut::<&'static mut WeakDom>().ok_or(mlua::Error::runtime("DataModel missing"))?;
|
||||||
|
@ -33,6 +33,7 @@ fn init(lua:&mlua::Lua)->mlua::Result<()>{
|
|||||||
super::color3::set_globals(lua,&globals)?;
|
super::color3::set_globals(lua,&globals)?;
|
||||||
super::vector3::set_globals(lua,&globals)?;
|
super::vector3::set_globals(lua,&globals)?;
|
||||||
super::cframe::set_globals(lua,&globals)?;
|
super::cframe::set_globals(lua,&globals)?;
|
||||||
|
super::instance::set_globals(lua,&globals)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user