rename dom function to avoid confusion with dom variable

This commit is contained in:
Quaternions 2024-10-05 11:45:10 -07:00
parent 7b8f091ab3
commit 136b360590

View File

@ -5,7 +5,7 @@ use rbx_dom_weak::{InstanceBuilder,WeakDom};
use super::vector3::Vector3; use super::vector3::Vector3;
// LMAO look at this function! // LMAO look at this function!
fn dom<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"))?;
f(&mut *dom) f(&mut *dom)
} }
@ -126,26 +126,26 @@ class_composition!(Instance,(Instance));
impl Instance{ impl Instance{
fn composition_add_fields<'lua,T:Referent,F:mlua::UserDataFields<'lua,T>>(fields:&mut F){ fn composition_add_fields<'lua,T:Referent,F:mlua::UserDataFields<'lua,T>>(fields:&mut F){
fields.add_field_method_get("Parent",|lua,this|{ fields.add_field_method_get("Parent",|lua,this|{
dom(lua,|dom|{ dom_mut(lua,|dom|{
let instance=this.get(dom)?; let instance=this.get(dom)?;
Ok(Instance::new(instance.parent())) Ok(Instance::new(instance.parent()))
}) })
}); });
fields.add_field_method_set("Parent",|lua,this,val:mlua::AnyUserData|{ fields.add_field_method_set("Parent",|lua,this,val:mlua::AnyUserData|{
let Dereferent(referent)=mlua::AnyUserDataExt::get(&val,"Referent")?; let Dereferent(referent)=mlua::AnyUserDataExt::get(&val,"Referent")?;
dom(lua,|dom|{ dom_mut(lua,|dom|{
dom.transfer_within(this.referent(),referent); dom.transfer_within(this.referent(),referent);
Ok(()) Ok(())
}) })
}); });
fields.add_field_method_get("Name",|lua,this|{ fields.add_field_method_get("Name",|lua,this|{
dom(lua,|dom|{ dom_mut(lua,|dom|{
let instance=this.get(dom)?; let instance=this.get(dom)?;
Ok(instance.name.clone()) Ok(instance.name.clone())
}) })
}); });
fields.add_field_method_set("Name",|lua,this,val:mlua::String|{ fields.add_field_method_set("Name",|lua,this,val:mlua::String|{
dom(lua,|dom|{ dom_mut(lua,|dom|{
let instance=this.get_mut(dom)?; let instance=this.get_mut(dom)?;
//Why does this need to be cloned? //Why does this need to be cloned?
instance.name=val.to_str()?.to_owned(); instance.name=val.to_str()?.to_owned();
@ -153,7 +153,7 @@ impl Instance{
}) })
}); });
fields.add_field_method_get("ClassName",|lua,this|{ fields.add_field_method_get("ClassName",|lua,this|{
dom(lua,|dom|{ dom_mut(lua,|dom|{
let instance=this.get(dom)?; let instance=this.get(dom)?;
Ok(instance.class.clone()) Ok(instance.class.clone())
}) })
@ -161,7 +161,7 @@ impl Instance{
} }
fn composition_add_methods<'lua,T:Referent,M:mlua::UserDataMethods<'lua,T>>(methods:&mut M){ fn composition_add_methods<'lua,T:Referent,M:mlua::UserDataMethods<'lua,T>>(methods:&mut M){
methods.add_method("GetChildren",|lua,this,_:()| methods.add_method("GetChildren",|lua,this,_:()|
dom(lua,|dom|{ dom_mut(lua,|dom|{
let instance=this.get(dom)?; let instance=this.get(dom)?;
let children:Vec<_>=instance let children:Vec<_>=instance
.children() .children()
@ -174,7 +174,7 @@ impl Instance{
); );
let ffc=|lua,this:&T,(name,search_descendants):(mlua::String,Option<bool>)|{ let ffc=|lua,this:&T,(name,search_descendants):(mlua::String,Option<bool>)|{
let name_str=name.to_str()?; let name_str=name.to_str()?;
dom(lua,|dom|{ dom_mut(lua,|dom|{
let instance=this.get(dom)?; let instance=this.get(dom)?;
Ok( Ok(
match search_descendants.unwrap_or(false){ match search_descendants.unwrap_or(false){
@ -191,7 +191,7 @@ impl Instance{
methods.add_method("WaitForChild",ffc); methods.add_method("WaitForChild",ffc);
methods.add_method("FindFirstChildOfClass",|lua,this,(class,search_descendants):(mlua::String,Option<bool>)|{ methods.add_method("FindFirstChildOfClass",|lua,this,(class,search_descendants):(mlua::String,Option<bool>)|{
let class_str=class.to_str()?; let class_str=class.to_str()?;
dom(lua,|dom|{ dom_mut(lua,|dom|{
Ok( Ok(
match search_descendants.unwrap_or(false){ match search_descendants.unwrap_or(false){
true=>find_first_descendant_of_class(dom,this.get(dom)?,class_str), true=>find_first_descendant_of_class(dom,this.get(dom)?,class_str),
@ -204,7 +204,7 @@ impl Instance{
}) })
}); });
methods.add_method("GetDescendants",|lua,this,_:()| methods.add_method("GetDescendants",|lua,this,_:()|
dom(lua,|dom|{ dom_mut(lua,|dom|{
let children:Vec<_>=dom let children:Vec<_>=dom
.descendants_of(this.referent()) .descendants_of(this.referent())
.map(|instance| .map(|instance|
@ -215,13 +215,13 @@ impl Instance{
}) })
); );
methods.add_method("IsA",|lua,this,classname:mlua::String| methods.add_method("IsA",|lua,this,classname:mlua::String|
dom(lua,|dom|{ dom_mut(lua,|dom|{
let instance=this.get(dom)?; let instance=this.get(dom)?;
Ok(crate::context::class_is_a(instance.class.as_str(),classname.to_str()?)) Ok(crate::context::class_is_a(instance.class.as_str(),classname.to_str()?))
}) })
); );
methods.add_method("Destroy",|lua,this,()| methods.add_method("Destroy",|lua,this,()|
dom(lua,|dom|{ dom_mut(lua,|dom|{
dom.destroy(this.referent()); dom.destroy(this.referent());
Ok(()) Ok(())
}) })
@ -229,7 +229,7 @@ impl Instance{
methods.add_meta_function(mlua::MetaMethod::Index,|lua,(this,index):(mlua::AnyUserData,mlua::String)|{ methods.add_meta_function(mlua::MetaMethod::Index,|lua,(this,index):(mlua::AnyUserData,mlua::String)|{
let index_str=index.to_str()?; let index_str=index.to_str()?;
let dereferent:Dereferent=mlua::AnyUserDataExt::get(&this,"Referent")?; let dereferent:Dereferent=mlua::AnyUserDataExt::get(&this,"Referent")?;
dom(lua,|dom|{ dom_mut(lua,|dom|{
let instance=dereferent.get(dom)?; let instance=dereferent.get(dom)?;
match instance.properties.get(index_str){ match instance.properties.get(index_str){
Some(&rbx_types::Variant::CFrame(cf))=>return Ok(Into::<super::cframe::CFrame>::into(cf).into_lua(lua)), Some(&rbx_types::Variant::CFrame(cf))=>return Ok(Into::<super::cframe::CFrame>::into(cf).into_lua(lua)),
@ -247,7 +247,7 @@ impl Instance{
}); });
methods.add_meta_function(mlua::MetaMethod::NewIndex,|lua,(this,index,value):(mlua::AnyUserData,mlua::String,mlua::Value)|{ methods.add_meta_function(mlua::MetaMethod::NewIndex,|lua,(this,index,value):(mlua::AnyUserData,mlua::String,mlua::Value)|{
let dereferent:Dereferent=mlua::AnyUserDataExt::get(&this,"Referent")?; let dereferent:Dereferent=mlua::AnyUserDataExt::get(&this,"Referent")?;
dom(lua,|dom|{ dom_mut(lua,|dom|{
let instance=dereferent.get_mut(dom)?; let instance=dereferent.get_mut(dom)?;
//println!("__newindex t={} i={index:?} v={value:?}",instance.name); //println!("__newindex t={} i={index:?} v={value:?}",instance.name);
let index_str=index.to_str()?; let index_str=index.to_str()?;
@ -308,7 +308,7 @@ class_composition!(DataModel,(Instance,DataModel));
impl DataModel{ impl DataModel{
fn composition_add_fields<'lua,T:Referent,F:mlua::UserDataFields<'lua,T>>(fields:&mut F){ fn composition_add_fields<'lua,T:Referent,F:mlua::UserDataFields<'lua,T>>(fields:&mut F){
fields.add_field_method_get("workspace",|lua,this|{ fields.add_field_method_get("workspace",|lua,this|{
dom(lua,|dom|{ dom_mut(lua,|dom|{
Ok(find_first_child_of_class(dom,this.get(dom)?,"Workspace") Ok(find_first_child_of_class(dom,this.get(dom)?,"Workspace")
.map(|inst|Workspace::new(inst.referent())) .map(|inst|Workspace::new(inst.referent()))
) )
@ -320,7 +320,7 @@ impl DataModel{
} }
fn composition_add_methods<'lua,T,M:mlua::UserDataMethods<'lua,T>>(methods:&mut M){ fn composition_add_methods<'lua,T,M:mlua::UserDataMethods<'lua,T>>(methods:&mut M){
methods.add_method("GetService",|lua,this,service:String| methods.add_method("GetService",|lua,this,service:String|
dom(lua,|dom|{ dom_mut(lua,|dom|{
match service.as_str(){ match service.as_str(){
"Lighting"=>{ "Lighting"=>{
let referent=find_first_child_of_class(dom,dom.root(),"Lighting") let referent=find_first_child_of_class(dom,dom.root(),"Lighting")
@ -342,7 +342,7 @@ class_composition!(Workspace,(Instance,Workspace));
impl Workspace{ impl Workspace{
fn composition_add_fields<'lua,T:Referent,F:mlua::UserDataFields<'lua,T>>(fields:&mut F){ fn composition_add_fields<'lua,T:Referent,F:mlua::UserDataFields<'lua,T>>(fields:&mut F){
fields.add_field_method_get("Terrain",|lua,this|{ fields.add_field_method_get("Terrain",|lua,this|{
dom(lua,|dom|{ dom_mut(lua,|dom|{
Ok(find_first_child_of_class(dom,this.get(dom)?,"Terrain") Ok(find_first_child_of_class(dom,this.get(dom)?,"Terrain")
.map(|inst|Terrain::new(inst.referent())) .map(|inst|Terrain::new(inst.referent()))
) )
@ -359,7 +359,7 @@ class!(Script);
class_composition!(Script,(Instance)); class_composition!(Script,(Instance));
impl Script{ impl Script{
pub fn get_name_source(&self,lua:&mlua::Lua)->Result<(String,String),mlua::Error>{ pub fn get_name_source(&self,lua:&mlua::Lua)->Result<(String,String),mlua::Error>{
dom(lua,|dom|{ dom_mut(lua,|dom|{
let instance=self.get(dom)?; let instance=self.get(dom)?;
let source=match instance.properties.get("Source"){ let source=match instance.properties.get("Source"){
Some(rbx_dom_weak::types::Variant::String(s))=>s.clone(), Some(rbx_dom_weak::types::Variant::String(s))=>s.clone(),