Update mount.lua
This commit is contained in:
parent
fb322a95e8
commit
d4f637eab7
1 changed files with 24 additions and 4 deletions
|
|
@ -2,6 +2,7 @@ local module = {};
|
||||||
|
|
||||||
function module.init(shared)
|
function module.init(shared)
|
||||||
local new = {};
|
local new = {};
|
||||||
|
local insert = table.insert;
|
||||||
|
|
||||||
local mount = {};
|
local mount = {};
|
||||||
mount.__index = mount;
|
mount.__index = mount;
|
||||||
|
|
@ -16,14 +17,33 @@ function module.init(shared)
|
||||||
end);
|
end);
|
||||||
local destroyThis = this.Destroy;
|
local destroyThis = this.Destroy;
|
||||||
if destroyThis then
|
if destroyThis then
|
||||||
pcall(destroyThis);
|
pcall(destroyThis,this);
|
||||||
end
|
end
|
||||||
|
--if sef.to when
|
||||||
|
-- todo for remove child on parent
|
||||||
end
|
end
|
||||||
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
|
-- we should add plugin support
|
||||||
function new.mount(to,this)
|
function new.mount(to,this,inst)
|
||||||
this.Parent = to;
|
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);
|
return setmetatable({to = to,this = this},mount);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue