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

View file

@ -7,7 +7,7 @@ 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();
@ -23,13 +23,17 @@ function module.init(shared)
-- todo for remove child on parent -- todo for remove child on parent
end end
end end
end
function new.getHolder(item) function new.getHolder(item)
return (type(item) == "table") and (item._holder or item.holder or item.__holder) or item; return (type(item) == "table") and (item._holder or item.holder or item.__holder) or item;
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;
function new.mount(to,...)
local items = pack(...);
for _,this in ipairs(items) do
local thisO = this; local thisO = this;
if type(this) == "table" then if type(this) == "table" then
thisO = this.__object; thisO = this.__object;
@ -47,7 +51,7 @@ function module.init(shared)
rawset(this,"__parent",to); rawset(this,"__parent",to);
end end
if thisO then if thisO then
thisO.Parent = inst or getHolder(to); thisO.Parent = getHolder(to);
end end
if type(to) == "table" then if type(to) == "table" then
local child = rawget(to,"__child"); local child = rawget(to,"__child");
@ -57,7 +61,8 @@ function module.init(shared)
end end
insert(child,this); insert(child,this);
end end
return setmetatable({to = to,this = this},mount); end
return setmetatable({to = to,this = items},mount);
end end
setmetatable(new,{ setmetatable(new,{