set script full name
This commit is contained in:
parent
1585e2f321
commit
c7c17243fb
@ -57,16 +57,20 @@ impl Runner{
|
||||
init(&runner.lua)?;
|
||||
Ok(runner)
|
||||
}
|
||||
pub fn set_script(&self,script:rbx_dom_weak::types::Ref)->mlua::Result<()>{
|
||||
pub fn set_script(&self,script:rbx_dom_weak::types::Ref,name:String)->mlua::Result<()>{
|
||||
//TODO: Instance type
|
||||
let script_table=self.lua.create_table()?;
|
||||
//script.Name
|
||||
script_table.raw_set("Name","Placeholder")?;
|
||||
script_table.raw_set("Name",name)?;
|
||||
self.lua.globals().set("script",script_table)?;
|
||||
Ok(())
|
||||
}
|
||||
pub fn run(&self,source:String,context:&mut crate::context::Context)->mlua::Result<()>{
|
||||
//Set up dom access here?
|
||||
self.lua.load(source).exec()
|
||||
let script:mlua::Table<'_>=self.lua.globals().raw_get("script")?;
|
||||
let name:String=script.raw_get("Name")?;
|
||||
self.lua.load(source)
|
||||
.set_name(name)
|
||||
.exec()
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,17 @@ impl Error{
|
||||
}
|
||||
}
|
||||
|
||||
fn get_full_name(dom:&rbx_dom_weak::WeakDom,instance:&rbx_dom_weak::Instance)->String{
|
||||
let mut full_name=instance.name.clone();
|
||||
let mut pref=instance.parent();
|
||||
while let Some(parent)=dom.get_by_ref(pref){
|
||||
full_name.insert(0,'.');
|
||||
full_name.insert_str(0,parent.name.as_str());
|
||||
pref=parent.parent();
|
||||
}
|
||||
full_name
|
||||
}
|
||||
|
||||
pub struct Script{
|
||||
script:Ref,
|
||||
}
|
||||
@ -26,16 +37,17 @@ impl Script{
|
||||
}
|
||||
pub fn run(&self,context:&mut crate::context::Context)->Result<(),Error>{
|
||||
// grab source
|
||||
let source={
|
||||
let (source,full_name)={
|
||||
let instance=context.dom.get_by_ref(self.script).ok_or(Error::NoScript)?;
|
||||
match instance.properties.get("Source").ok_or(Error::NoSource)?{
|
||||
let source=match instance.properties.get("Source").ok_or(Error::NoSource)?{
|
||||
rbx_dom_weak::types::Variant::String(s)=>s.clone(),
|
||||
_=>Err(Error::NoSource)?,
|
||||
}
|
||||
};
|
||||
(source,get_full_name(&context.dom,instance))
|
||||
};
|
||||
// run it lole
|
||||
let runner=crate::runner::Runner::new().map_err(Error::Runner)?;
|
||||
runner.set_script(self.script).map_err(Error::Runner)?;
|
||||
runner.set_script(self.script,full_name).map_err(Error::Runner)?;
|
||||
runner.run(source,context).map_err(Error::Runner)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user