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

View file

@ -4,9 +4,9 @@ function module.init(shared)
local new = {};
local insert = table.insert;
local mount = {};
mount.__index = mount;
function mount:unmount()
local mountClass = {};
mountClass.__index = mountClass;
function mountClass:unmount()
local this = self.this
local typeThis = type(this);
if typeThis == "userdata" then
@ -27,7 +27,8 @@ function module.init(shared)
function new.getHolder(item)
return (type(item) == "table") and (item._holder or item.holder or item.__holder) or item;
end
local getHolder = new.getHolder
local getHolder = new.getHolder;
-- we should add plugin support
function new.mount(to,this,holder)
local thisObject = this;
@ -57,12 +58,30 @@ function module.init(shared)
end
insert(child,this);
end
return setmetatable({to = to,this = this},mount);
return setmetatable({to = to,this = this},mountClass);
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,{
__call = function (self,...)
return new.mount(...);
__call = function (self,to,...)
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;
});

View file

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