get referent from any class
This commit is contained in:
parent
6c12bc2bf6
commit
40655cdf44
@ -29,6 +29,11 @@ fn get_full_name(dom:&rbx_dom_weak::WeakDom,instance:&rbx_dom_weak::Instance)->S
|
||||
full_name
|
||||
}
|
||||
|
||||
//workaround until I have an enum of classes
|
||||
struct Dereferent(Ref);
|
||||
impl mlua::UserData for Dereferent{}
|
||||
type_from_lua_userdata!(Dereferent);
|
||||
|
||||
trait Referent{
|
||||
fn referent(&self)->Ref;
|
||||
fn get<'a>(&self,dom:&'a WeakDom)->mlua::Result<&'a rbx_dom_weak::Instance>{
|
||||
@ -61,6 +66,9 @@ macro_rules! class_composition{
|
||||
($class:ident,($($superclass:ident),*))=>{
|
||||
impl mlua::UserData for $class{
|
||||
fn add_fields<'lua,F:mlua::UserDataFields<'lua,Self>>(fields:&mut F){
|
||||
fields.add_field_method_get("Referent",|_,this|{
|
||||
Ok(Dereferent(this.referent()))
|
||||
});
|
||||
$(
|
||||
$superclass::composition_add_fields(fields);
|
||||
)*
|
||||
@ -86,9 +94,10 @@ impl Instance{
|
||||
Ok(Instance::new(instance.parent()))
|
||||
})
|
||||
});
|
||||
fields.add_field_method_set("Parent",|lua,this,val:Self|{
|
||||
fields.add_field_method_set("Parent",|lua,this,val:mlua::AnyUserData|{
|
||||
let Dereferent(referent)=mlua::AnyUserDataExt::get(&val,"Referent")?;
|
||||
dom(lua,|dom|{
|
||||
dom.transfer_within(this.referent(),val.referent);
|
||||
dom.transfer_within(this.referent(),referent);
|
||||
Ok(())
|
||||
})
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user