big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-22 16:24:00 +02:00
parent 54c082cff9
commit c0f8aece7e
11 changed files with 94 additions and 106 deletions
+40 -50
View File
@@ -1,5 +1,5 @@
function INIT()
import :_ 'core' :_ 'control' :_ 'util'
import :_ 'core' :_ 'control' :_ 'util' -- TODO auto import 'core' instead
end
module 'core'
@@ -8,7 +8,7 @@ public.version = '5.0.0'
do
local table_pool, temporary = {}, {}
CreateFrame 'Frame' :SetScript('OnUpdate', function()
CreateFrame'Frame':SetScript('OnUpdate', function()
for t in temporary do
recycle(t)
log(getn(table_pool))
@@ -24,48 +24,57 @@ do
end
function public.recycle(t)
auto_recycle[t] = nil
temporary[t] = nil
wipe(t)
tinsert(table_pool, t)
end
function public.getter.t() return
function public.accessor.t() return
tremove(table_pool) or {}
end
function public.getter.tt()
function public.accessor.tt()
local t = tremove(table_pool) or {}
temporary[t] = true
return t
end
public.tmp = setmetatable({}, {__sub = function(_, t) temporary[t] = true return t end})
do
local mt = {
__call=function(self, arg) return self[1](arg) end,
__sub=function(self, arg) return self[1](arg) end,
}
function public.modifier(f)
local self = t
self[1] = f
return setmetatable(self, mt)
end
end
public.tmp = modifier(function(t)
temporary[t] = true
return t
end)
do
local mt = {
__call=function(self, arg1, arg2) tinsert(self, arg2 or arg1); return self; end,
__index=function(self, key) tinsert(self, key); return self; end,
__call=function(self, arg1, arg2)
tinsert(self, arg2 or arg1)
return self
end,
__index=function(self, key)
tinsert(self, key)
return self
end,
}
function public.getter.from()
function public.accessor.from()
return setmetatable(tt, mt)
end
end
do
local mt = {
__call=function(self, arg) return self[1](arg) end,
__unm=function(self, arg) return self[1](arg) end,
}
function public.modifier(f)
local self = t; t[1] = f
return setmetatable(self, mt)
end
end
do
local mt = {__call = function(self, key) return self[key] end}
public.getter.set = modifier(function(table)
public.set = modifier(function(table)
local self = t
for _, v in table do self[v] = true end
recycle(table)
@@ -73,45 +82,26 @@ do
end)
end
public.array = modifier(function(table)
local self = t
for _, v in table do tinsert(self, v) end
recycle(table)
return self
end)
function public.array(table)
local array = t
for k, v in table do tinsert(array, v) end
return array
end
do
local mt = {
__call=function(self, arg1, arg2) self[arg2 or arg1] = true; return self; end,
__index=function(self, key) self[key] = true; return self; end,
}
function public.getter.metaset()
return setmetatable(t, mt)
end
end
do
local mt = {
__call=function(self, arg1, arg2) self[arg2 or arg1] = true; return self; end,
__index=function(self, key) tinsert(self, key); return self; end,
}
function public.getter.metamap()
return setmetatable(t, mt)
end
end
-- TODO map
end
local event_frame = CreateFrame 'Frame'
for _, event in tmp-{'ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE'} do
for event in tmp-set-from . ADDON_LOADED . VARIABLES_LOADED . PLAYER_LOGIN . AUCTION_HOUSE_SHOW . AUCTION_HOUSE_CLOSED . AUCTION_BIDDER_LIST_UPDATE . AUCTION_OWNED_LIST_UPDATE do
event_frame:RegisterEvent(event)
end
ADDON_LOADED = t
do
local variables_loaded_hooks, player_login_hooks = t, t
function public.setter.LOAD(f) tinsert(variables_loaded_hooks, f) end
function public.setter.LOAD2(f) tinsert(player_login_hooks, f) end
function public.mutator.LOAD(f) tinsert(variables_loaded_hooks, f) end
function public.mutator.LOAD2(f) tinsert(player_login_hooks, f) end
event_frame:SetScript('OnEvent', function()
if event == 'ADDON_LOADED' then
if ADDON_LOADED[arg1] then ADDON_LOADED[arg1]() end