naming improve

This commit is contained in:
세젤귀 고양이들 2022-01-01 20:59:05 +09:00
parent a6bc37dbc7
commit 6e3e33e024
3 changed files with 45 additions and 26 deletions

View file

@ -76,17 +76,17 @@ function module.init(shared)
-- roblox connections disconnecter -- roblox connections disconnecter
local insert = table.insert; local insert = table.insert;
local idSpace = {}; local idSpace = {};
local disconnecter = {}; local disconnecterClass = {};
function disconnecter:add(connection) function disconnecterClass:add(connection)
insert(self,connection); insert(self,connection);
end end
function disconnecter:disconnect() function disconnecterClass:disconnect()
for i,v in pairs(self) do for i,v in pairs(self) do
pcall(v.Disconnect,v); pcall(v.Disconnect,v);
self[i] = nil; self[i] = nil;
end end
end end
function disconnecter:destroy() function disconnecterClass:destroy()
local id = self.id; local id = self.id;
if id then if id then
idSpace[id] = nil; idSpace[id] = nil;
@ -96,7 +96,7 @@ function module.init(shared)
self[i] = nil; self[i] = nil;
end end
end end
disconnecter.__index = disconnecter; disconnecterClass.__index = disconnecterClass;
function new.new(id) function new.new(id)
if id then if id then
local old = idSpace[id]; local old = idSpace[id];
@ -104,7 +104,7 @@ function module.init(shared)
return old; return old;
end end
end end
local this = setmetatable({id = id},disconnecter); local this = setmetatable({id = id},disconnecterClass);
if id then if id then
idSpace[id] = this; idSpace[id] = this;
end end

View file

@ -4,9 +4,9 @@ function module.init(shared)
local new = {}; local new = {};
local insert = table.insert; local insert = table.insert;
local mount = {}; local mountClass = {};
mount.__index = mount; mountClass.__index = mountClass;
function mount:unmount() function mountClass:unmount()
local this = self.this local this = self.this
local typeThis = type(this); local typeThis = type(this);
if typeThis == "userdata" then if typeThis == "userdata" then
@ -27,7 +27,8 @@ function module.init(shared)
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,holder) function new.mount(to,this,holder)
local thisObject = this; local thisObject = this;
@ -57,12 +58,30 @@ function module.init(shared)
end end
insert(child,this); insert(child,this);
end end
return setmetatable({to = to,this = this},mount); return setmetatable({to = to,this = this},mountClass);
end end
local mount = new.mount;
local pack = table.pack;
local mountsClass = {};
mountsClass.__index = mountsClass;
function mountsClass:unmount()
for _,v in ipairs(self) do
v:unmount();
end
end
setmetatable(new,{ setmetatable(new,{
__call = function (self,...) __call = function (self,to,...)
return new.mount(...); if select("#",...) == 1 then
return new.mount(to,...);
end
local mounts = {};
local items = pack(...);
for _,item in ipairs(items) do
insert(mounts,mount(to,item));
end
setmetatable(mounts,mountsClass);
return mounts;
end; end;
}); });

View file

@ -22,13 +22,13 @@ function module.init(shared)
local items = shared.items; local items = shared.items;
-- id space (array of object) -- id space (array of object)
local objSpace = {}; local objSpaceClass = {};
function objSpace:each(func) function objSpaceClass:each(func)
for i,v in ipairs(self) do for i,v in ipairs(self) do
wrap(catch)(func,i,v); wrap(catch)(func,i,v);
end end
end end
function objSpace:eachSync(func) function objSpaceClass:eachSync(func)
for i,v in ipairs(self) do for i,v in ipairs(self) do
local ret = func(i,v); local ret = func(i,v);
if ret then if ret then
@ -36,7 +36,7 @@ function module.init(shared)
end end
end end
end end
function objSpace:remove(indexOrItem) function objSpaceClass:remove(indexOrItem)
local thisType = type(indexOrItem); local thisType = type(indexOrItem);
if thisType == "number" then if thisType == "number" then
remove(self,indexOrItem); remove(self,indexOrItem);
@ -49,16 +49,16 @@ function module.init(shared)
end end
end end
end end
function objSpace.__new() function objSpaceClass.__new()
return setmetatable({},objSpace); return setmetatable({},objSpaceClass);
end end
function objSpace:__newIndex(key,value) -- props setter function objSpaceClass:__newIndex(key,value) -- props setter
self:each(function (this) self:each(function (this)
this[key] = value; this[key] = value;
end); end);
end end
objSpace.__mode = "kv"; -- week link for gc objSpaceClass.__mode = "kv"; -- week link for gc
objSpace.__index = objSpace; objSpaceClass.__index = objSpaceClass;
-- get object array with id (objSpace) -- get object array with id (objSpace)
function new.getObjects(id) function new.getObjects(id)
@ -77,14 +77,14 @@ function module.init(shared)
id = id:gsub("^ +",""):gsub(" +$",""); id = id:gsub("^ +",""):gsub(" +$","");
local array = items[id]; local array = items[id];
if not array then if not array then
array = objSpace.__new(); array = objSpaceClass.__new();
items[id] = array; items[id] = array;
end end
insert(array, object); insert(array, object);
end end
end end
local registerMt = { local registerClass = {
register = function (s,efunc) register = function (s,efunc)
local self = s.store; local self = s.store;
local events = self.__evt; local events = self.__evt;
@ -111,7 +111,7 @@ function module.init(shared)
return setmetatable({fvalue = value},{__index = s}); return setmetatable({fvalue = value},{__index = s});
end; end;
}; };
registerMt.__index = registerMt; registerClass.__index = registerClass;
-- bindable store object -- bindable store object
local store = {}; local store = {};
@ -135,7 +135,7 @@ function module.init(shared)
key = key; key = key;
store = self; store = self;
t = "reg"; t = "reg";
},registerMt); },registerClass);
self.__reg[key] = register; self.__reg[key] = register;
end end