big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-21 15:22:16 +02:00
parent a054bb8cff
commit 59f00ff578
9 changed files with 72 additions and 79 deletions
+7 -7
View File
@@ -37,15 +37,15 @@ do
call(on_complete)
end
function accessor.state()
local _, state = next(filter(scan_states, function(state) return state.id == control.thread_id end))
return state
end
private.state{
get = function()
local _, state = next(filter(scan_states, function(state) return state.id == control.thread_id end))
return state
end,
}
end
function accessor.query()
return state.params.queries[state.query_index]
end
private.query{get=function() return state.params.queries[state.query_index] end}
function wait_for_callback(...)
local send_signal, signal_received = signal()
+1 -4
View File
@@ -44,10 +44,7 @@ end
do
local id = 0
function accessor.id()
id = id + 1
return id
end
private.id{get=function() id = id + 1; return id end}
end
function public.kill_listener(listener_id)
+4 -4
View File
@@ -63,13 +63,13 @@ tabs = {}
function public.tab(index, name)
local module_env = getfenv(2)
local tab = {name=name, env=module_env}
module_env.public.accessor.ACTIVE = function() return tab == active_tab end
module_env.public.ACTIVE{get=function() return tab == active_tab end}
for _, handler in temp-{'OPEN', 'CLOSE', 'CLICK_LINK', 'USE_ITEM'} do module_env.mutable[handler] = nil end
tabs[index] = tab
end
do
local active_tab_index
function accessor.active_tab() return tabs[active_tab_index] end
private.active_tab{get=function() return tabs[active_tab_index] end}
function on_tab_click(index)
call(active_tab_index and active_tab.env.CLOSE)
active_tab_index = index
@@ -88,7 +88,7 @@ end
do
local locked
function public.accessor.bid_in_progress() return locked end
public.bid_in_progress{get=function() return locked end}
function public.place_bid(type, index, amount, on_success)
if locked then
return
@@ -110,7 +110,7 @@ end
do
local locked
function public.accessor.cancel_in_progress() return locked end
public.cancel_in_progress{get=function() return locked end}
function public.cancel_auction(index, on_success)
if locked then
return
+13 -12
View File
@@ -60,23 +60,24 @@ do
end
end
}
public.accessor.color = color_accessor(function(color)
local r, g, b, a = unpack(color)
return setmetatable({r/255, g/255, b/255, a}, mt)
end)
public.color{
get = color_accessor(function(color)
local r, g, b, a = unpack(color)
return setmetatable({r/255, g/255, b/255, a}, mt)
end),
}
end
public.accessor.inline_color = color_accessor(function(color)
local r, g, b, a = unpack(color)
return format('|c%02X%02X%02X%02X', a, r, g, b)
end)
public.inline_color{
get = color_accessor(function(color)
local r, g, b, a = unpack(color)
return format('|c%02X%02X%02X%02X', a, r, g, b)
end),
}
do
local id = 0
function public.accessor.name()
id = id + 1
return 'aux_frame'..id
end
public.name{get=function() id = id + 1; return 'aux_frame'..id end}
end
do
+15 -15
View File
@@ -1,5 +1,6 @@
local aux_module, getn, setn, tinsert, tremove, setfenv = aux_module, getn, table.setn, tinsert, tremove, setfenv
aux = aux_module 'core'
local aux_module, setn, tinsert, tremove, setfenv = aux_module, table.setn, tinsert, tremove, setfenv
local aux = aux_module 'core'
_g.aux = aux.interface
public.version = '5.0.0'
do
@@ -12,10 +13,10 @@ do
function public.recycle(t)
auto_recycle[t] = nil
tinsert(table_pool, wipe(t))
log(getn(table_pool))
-- log(getn(table_pool))
end
public.temp = setmetatable({}, {__sub = function(_, t) auto_recycle[t] = true return t end})
function public.accessor.t() return tremove(table_pool) or {} end
public.t{get=function() return tremove(table_pool) or {} end}
CreateFrame('Frame'):SetScript('OnUpdate', function()
for t in auto_recycle do recycle(t) end
recycle(auto_recycle)
@@ -25,8 +26,9 @@ end
do
local modules = {}
local function module_env(name) aux_module(name) return _m end
function public.module(name)
local env = aux_module(name).env
local env = module_env(name)
if not modules[name] then env.import(temp-{['']='modules', ['']='core', ['']='util'}) end
setfenv(2, env)
modules[name] = true
@@ -34,27 +36,25 @@ do
end
local event_frame = CreateFrame 'Frame'
for _, event in temp-{'VARIABLES_LOADED', 'ADDON_LOADED', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE'} do
for _, event in temp-{'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 = {}
do
local variables_loaded_hooks, player_login_hooks = t, t
function public.mutator.LOAD(f) tinsert(variables_loaded_hooks, f) end
function public.mutator.LOAD2(f) tinsert(player_login_hooks, f) end
public.LOAD{set=function(f) tinsert(variables_loaded_hooks, f) end}
public.LOAD2{set=function(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
elseif event == 'VARIABLES_LOADED' then
for _, f in variables_loaded_hooks do f() end
elseif event == 'PLAYER_LOGIN' then
for _, f in player_login_hooks do f() end
log('v'..version..' loaded.')
else
_m[event]()
if event == 'VARIABLES_LOADED' then
for _, f in variables_loaded_hooks do f() end
end
if event == 'PLAYER_LOGIN' then
for _, f in player_login_hooks do f() end
log('v'..version..' loaded.')
end
end
end)
end
+6 -5
View File
@@ -3,6 +3,7 @@ local PRIVATE, PUBLIC, MUTABLE, PROPERTY = 0, 1, 2, 4
local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE, property=PROPERTY}
local MODIFIER_MASK, PROPERTY_MASK = {private=MUTABLE+PROPERTY, public=MUTABLE+PROPERTY, mutable=PRIVATE+PUBLIC}, PRIVATE+PUBLIC
local error, import, define_property, lock_mt, env_mt, interface_mt, declarator_mt
lock_mt = {}
local _state, _modules = {}, {}
function error(message, level, ...) _g.error(format(message, unpack(arg))..'\n'..debugstack(3, 5, 0), (level or 1) + 1) end
function import(imports, t) for k, v in t do imports[type(k) == 'number' and v or k] = v end end
@@ -37,12 +38,12 @@ end
do
local function index(access, default)
return function(self, key)
local state = _state[self]; local modifiers = state.metadata[key] or error('No field "%s".', 2, key)
if mask(access+PROPERTY, modifiers) == access then
local state = _state[self]; local modifiers = state.metadata[key]
if modifiers and mask(access+PROPERTY, modifiers) == access then
return state.data[key]
else
local getter = state.getters[key]
if getter then return getter() else return default[key] end
if getter then return getter() else return default[key] or error('No field "%s".', 2, key) end
end
end
end
@@ -69,12 +70,12 @@ do
end
end
function _g.aux_module(name)
if not _state[name] then
if not _modules[name] then
local state, declarator, env, interface, imports
env, interface, declarator, imports = setmetatable({}, env_mt), setmetatable({}, interface_mt), setmetatable({}, declarator_mt), {}
state = {
name = name, env = env, interface = interface, declarator = declarator, imports = {}, declarator_state = PRIVATE,
metadata={_g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=PROPERTY, public=PROPERTY, getter=PROPERTY, setter=PROPERTY, mutable=PROPERTY},
metadata = {_g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=PROPERTY, public=PROPERTY, getter=PROPERTY, setter=PROPERTY, mutable=PROPERTY},
data = {_g=_g, _m=env, _i=interface, import=function(t) import(imports, t) end},
getters = {private=function() state.modifiers = PRIVATE return declarator end, public=function() state.modifiers = PUBLIC return declarator end, mutable=function() state.modifiers = MUTABLE return declarator end},
setters = {},
+1 -3
View File
@@ -9,9 +9,7 @@ do
local searches = {}
local search_index = 1
function accessor.current_search()
return searches[search_index]
end
private.current_search{get=function() return searches[search_index] end}
function update_search(index)
searches[search_index].status_bar:Hide()
+24 -26
View File
@@ -1,6 +1,6 @@
aux.module 'util'
local temp, recycle, getn = temp, recycle, _g.getn
local temp, recycle, getn = _g.aux.temp, _g.aux.recycle, _g.getn
function public.copy(t)
local copy = {}
@@ -25,11 +25,13 @@ do
end
end
for i=1,9 do public[join{replicate(i, 'x')}] = setter(i) end
function public.accessor.__()
assert(charges > 0)
charges = charges - 1
return value
end
public.__{
get = function()
assert(charges > 0)
charges = charges - 1
return value
end,
}
end
do
@@ -40,8 +42,7 @@ do
return tmp
end
function public.present(v)
state = v
return f
state = v; return f
end
end
@@ -88,9 +89,7 @@ end
public.huge = 1.8*10^308
function public.accessor.modified()
return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown()
end
public.modified{get=function() return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() end}
--do TODO
-- local _state = setmetatable({}, {__mode='kv'})
@@ -123,10 +122,7 @@ function public.expand(array, ...)
end
function public.select(i, ...)
while i > 1 do
i = i - 1
tremove(arg, i)
end
while i > 1 do i = i - 1; tremove(arg, i) end
return tremove(arg, 1), unpack(arg)
end
@@ -251,18 +247,20 @@ end
function public.round(x) return floor(x + 0.5) end
function public.accessor.inventory()
local bag, slot = 0, 0
return function()
if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then
repeat bag = bag + 1 until GetBagName(bag) or bag > 4
slot = 1
else
slot = slot + 1
public.inventory{
get = function()
local bag, slot = 0, 0
return function()
if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then
repeat bag = bag + 1 until GetBagName(bag) or bag > 4
slot = 1
else
slot = slot + 1
end
if bag <= 4 then return {bag, slot}, bag_type(bag) end
end
if bag <= 4 then return {bag, slot}, bag_type(bag) end
end
end
end,
}
function public.bag_type(bag)
if bag == 0 then
+1 -3
View File
@@ -10,9 +10,7 @@ do
realm = GetCVar 'realmName'
end
function accessor.dataset_key()
return realm..'|'..faction
end
private.dataset_key{get=function() return realm..'|'..faction end}
end
function public.load_dataset()