test
This commit is contained in:
parent
f3881af24f
commit
9189cbcd92
1 changed files with 42 additions and 37 deletions
|
|
@ -7,20 +7,21 @@ function module.init(shared)
|
|||
local mount = {};
|
||||
mount.__index = mount;
|
||||
function mount:unmount()
|
||||
local this = self.this;
|
||||
local typeThis = type(this);
|
||||
if typeThis == "userdata" then
|
||||
this:Destroy();
|
||||
elseif typeThis == "table" then
|
||||
pcall(function()
|
||||
this.Parent = nil;
|
||||
end);
|
||||
local destroyThis = this.Destroy;
|
||||
if destroyThis then
|
||||
pcall(destroyThis,this);
|
||||
for _,this in ipairs(self.items) do
|
||||
local typeThis = type(this);
|
||||
if typeThis == "userdata" then
|
||||
this:Destroy();
|
||||
elseif typeThis == "table" then
|
||||
pcall(function()
|
||||
this.Parent = nil;
|
||||
end);
|
||||
local destroyThis = this.Destroy;
|
||||
if destroyThis then
|
||||
pcall(destroyThis,this);
|
||||
end
|
||||
--if sef.to when
|
||||
-- todo for remove child on parent
|
||||
end
|
||||
--if sef.to when
|
||||
-- todo for remove child on parent
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -29,35 +30,39 @@ function module.init(shared)
|
|||
end
|
||||
local getHolder = new.getHolder
|
||||
-- we should add plugin support
|
||||
function new.mount(to,this,inst)
|
||||
local thisO = this;
|
||||
if type(this) == "table" then
|
||||
thisO = this.__object;
|
||||
local parent = rawget(this,"__parent");
|
||||
if type(parent) == "table" then
|
||||
local parentChild = rawget(parent,"__child");
|
||||
if parentChild then
|
||||
for i,v in pairs(parentChild) do
|
||||
if v == this then
|
||||
parentChild[i] = nil;
|
||||
local pack = table.pack;
|
||||
function new.mount(to,...)
|
||||
local items = pack(...);
|
||||
for _,this in ipairs(items) do
|
||||
local thisO = this;
|
||||
if type(this) == "table" then
|
||||
thisO = this.__object;
|
||||
local parent = rawget(this,"__parent");
|
||||
if type(parent) == "table" then
|
||||
local parentChild = rawget(parent,"__child");
|
||||
if parentChild then
|
||||
for i,v in pairs(parentChild) do
|
||||
if v == this then
|
||||
parentChild[i] = nil;
|
||||
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
|
||||
rawset(this,"__parent",to);
|
||||
end
|
||||
if thisO then
|
||||
thisO.Parent = inst or 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
|
||||
return setmetatable({to = to,this = this},mount);
|
||||
return setmetatable({to = to,this = items},mount);
|
||||
end
|
||||
|
||||
setmetatable(new,{
|
||||
|
|
|
|||
Loading…
Reference in a new issue