This commit is contained in:
세젤귀 고양이들 2022-01-01 20:36:11 +09:00
parent f3881af24f
commit 9189cbcd92

View file

@ -7,20 +7,21 @@ function module.init(shared)
local mount = {}; local mount = {};
mount.__index = mount; mount.__index = mount;
function mount:unmount() function mount:unmount()
local this = self.this; for _,this in ipairs(self.items) do
local typeThis = type(this); local typeThis = type(this);
if typeThis == "userdata" then if typeThis == "userdata" then
this:Destroy(); this:Destroy();
elseif typeThis == "table" then elseif typeThis == "table" then
pcall(function() pcall(function()
this.Parent = nil; this.Parent = nil;
end); end);
local destroyThis = this.Destroy; local destroyThis = this.Destroy;
if destroyThis then if destroyThis then
pcall(destroyThis,this); pcall(destroyThis,this);
end
--if sef.to when
-- todo for remove child on parent
end end
--if sef.to when
-- todo for remove child on parent
end end
end end
@ -29,35 +30,39 @@ function module.init(shared)
end end
local getHolder = new.getHolder local getHolder = new.getHolder
-- we should add plugin support -- we should add plugin support
function new.mount(to,this,inst) local pack = table.pack;
local thisO = this; function new.mount(to,...)
if type(this) == "table" then local items = pack(...);
thisO = this.__object; for _,this in ipairs(items) do
local parent = rawget(this,"__parent"); local thisO = this;
if type(parent) == "table" then if type(this) == "table" then
local parentChild = rawget(parent,"__child"); thisO = this.__object;
if parentChild then local parent = rawget(this,"__parent");
for i,v in pairs(parentChild) do if type(parent) == "table" then
if v == this then local parentChild = rawget(parent,"__child");
parentChild[i] = nil; if parentChild then
for i,v in pairs(parentChild) do
if v == this then
parentChild[i] = nil;
end
end end
end end
end end
rawset(this,"__parent",to);
end
if thisO then
thisO.Parent = getHolder(to);
end
if type(to) == "table" then
local child = rawget(to,"__child");
if not child then
child = {};
rawset(to,"__child",child);
end
insert(child,this);
end end
rawset(this,"__parent",to);
end
if thisO then
thisO.Parent = inst or getHolder(to);
end end
if type(to) == "table" then return setmetatable({to = to,this = items},mount);
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 end
setmetatable(new,{ setmetatable(new,{