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