From d4f637eab78a0c528978f30e75df7ae8c8b6807f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=84=B8=EC=A0=A4=EA=B7=80=20=EA=B3=A0=EC=96=91=EC=9D=B4?= =?UTF-8?q?=EB=93=A4?= <46598063+qwreey75@users.noreply.github.com> Date: Fri, 24 Dec 2021 19:44:50 +0900 Subject: [PATCH] Update mount.lua --- src/mount.lua | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/mount.lua b/src/mount.lua index 36d9522..44aba9a 100644 --- a/src/mount.lua +++ b/src/mount.lua @@ -2,6 +2,7 @@ local module = {}; function module.init(shared) local new = {}; + local insert = table.insert; local mount = {}; mount.__index = mount; @@ -16,14 +17,33 @@ function module.init(shared) end); local destroyThis = this.Destroy; if destroyThis then - pcall(destroyThis); + pcall(destroyThis,this); end + --if sef.to when + -- todo for remove child on parent end end + function new.getHolder(item) + return (type(item) == "table") and (item._holder or item.holder or item.__holder) or item; + end + local getHolder = new.getHolder -- we should add plugin support - function new.mount(to,this) - this.Parent = to; + function new.mount(to,this,inst) + local thisO = this; + if type(this) == "table" then + thisO = this.__object; + rawset(this,"__parent",to); + end + thisO.Parent = inst or getHolder(to); + if type(to) == "table" then + local child = rawget(to,"__child"); + if not child then + child = {}; + rawset(to,"__child",child); + end + insert(child,this): + end return setmetatable({to = to,this = this},mount); end @@ -36,4 +56,4 @@ function module.init(shared) return new; end -return module; \ No newline at end of file +return module;