big refactoring
This commit is contained in:
+16
-18
@@ -41,25 +41,23 @@ do
|
||||
end
|
||||
|
||||
function LOAD()
|
||||
armor = set(
|
||||
'INVTYPE_HEAD',
|
||||
'INVTYPE_NECK',
|
||||
'INVTYPE_SHOULDER',
|
||||
'INVTYPE_BODY',
|
||||
'INVTYPE_CHEST',
|
||||
'INVTYPE_ROBE',
|
||||
'INVTYPE_WAIST',
|
||||
'INVTYPE_LEGS',
|
||||
'INVTYPE_FEET',
|
||||
'INVTYPE_WRIST',
|
||||
'INVTYPE_HAND',
|
||||
'INVTYPE_FINGER',
|
||||
'INVTYPE_TRINKET',
|
||||
'INVTYPE_CLOAK',
|
||||
armor = set-from
|
||||
'INVTYPE_HEAD'
|
||||
'INVTYPE_NECK'
|
||||
'INVTYPE_SHOULDER'
|
||||
'INVTYPE_BODY'
|
||||
'INVTYPE_CHEST'
|
||||
'INVTYPE_ROBE'
|
||||
'INVTYPE_WAIST'
|
||||
'INVTYPE_LEGS'
|
||||
'INVTYPE_FEET'
|
||||
'INVTYPE_WRIST'
|
||||
'INVTYPE_HAND'
|
||||
'INVTYPE_FINGER'
|
||||
'INVTYPE_TRINKET'
|
||||
'INVTYPE_CLOAK'
|
||||
'INVTYPE_HOLDABLE'
|
||||
)
|
||||
|
||||
weapon = set
|
||||
weapon = set-from
|
||||
'INVTYPE_2HWEAPON'
|
||||
'INVTYPE_WEAPONMAINHAND'
|
||||
'INVTYPE_WEAPON'
|
||||
|
||||
+2
-2
@@ -37,13 +37,13 @@ do
|
||||
call(on_complete)
|
||||
end
|
||||
|
||||
function getter.state()
|
||||
function accessor.state()
|
||||
local _, state = next(filter(scan_states, function(state) return state.id == thread_id end))
|
||||
return state
|
||||
end
|
||||
end
|
||||
|
||||
function getter.query() return state.params.queries[state.query_index] end
|
||||
function accessor.query() return state.params.queries[state.query_index] end
|
||||
|
||||
function wait_for_callback(...)
|
||||
local send_signal, signal_received = signal()
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ end
|
||||
|
||||
do
|
||||
local id = 0
|
||||
function getter.id() id = id + 1; return id end
|
||||
function accessor.id() id = id + 1; return id end
|
||||
end
|
||||
|
||||
function public.kill_listener(listener_id)
|
||||
|
||||
@@ -64,13 +64,13 @@ tabs = {}
|
||||
function public.tab(index, name)
|
||||
local module_env = getfenv(2)
|
||||
local tab = {name=name, env=module_env}
|
||||
function module_env.public.getter.ACTIVE() return tab == active_tab end
|
||||
for _, handler in tmp-{'OPEN', 'CLOSE', 'CLICK_LINK', 'USE_ITEM'} do module_env.mutable[handler] = nil end
|
||||
function module_env.public.accessor.ACTIVE() return tab == active_tab end
|
||||
for handler in tmp-set-from . OPEN . CLOSE . CLICK_LINK . USE_ITEM do module_env.mutable[handler] = nil end
|
||||
tabs[index] = tab
|
||||
end
|
||||
do
|
||||
local active_tab_index
|
||||
function getter.active_tab() return tabs[active_tab_index] end
|
||||
function accessor.active_tab() return tabs[active_tab_index] end
|
||||
function on_tab_click(index)
|
||||
call(active_tab_index and active_tab.env.CLOSE)
|
||||
active_tab_index = index
|
||||
@@ -89,7 +89,7 @@ end
|
||||
|
||||
do
|
||||
local locked
|
||||
function public.getter.bid_in_progress() return locked end
|
||||
function public.accessor.bid_in_progress() return locked end
|
||||
function public.place_bid(type, index, amount, on_success)
|
||||
if locked then return end
|
||||
local money = GetMoney()
|
||||
@@ -109,7 +109,7 @@ end
|
||||
|
||||
do
|
||||
local locked
|
||||
function public.getter.cancel_in_progress() return locked end
|
||||
function public.accessor.cancel_in_progress() return locked end
|
||||
function public.cancel_auction(index, on_success)
|
||||
if locked then return end
|
||||
locked = true
|
||||
|
||||
@@ -60,20 +60,20 @@ do
|
||||
end
|
||||
end
|
||||
}
|
||||
public.getter.color = color_accessor(function(color)
|
||||
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)
|
||||
end
|
||||
|
||||
public.getter.inline_color = color_accessor(function(color)
|
||||
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)
|
||||
|
||||
do
|
||||
local id = 0
|
||||
function public.getter.name() id = id + 1; return 'aux_frame'..id end
|
||||
function public.accessor.name() id = id + 1; return 'aux_frame'..id end
|
||||
end
|
||||
|
||||
do
|
||||
|
||||
@@ -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
|
||||
|
||||
+17
-17
@@ -1,7 +1,7 @@
|
||||
local type, setmetatable, setfenv, unpack, mask, _g = type, setmetatable, setfenv, unpack, bit.band, getfenv(0)
|
||||
local PRIVATE, PUBLIC, MUTABLE, PROPERTY, GETTER, SETTER = 0, 1, 2, 4, 8, 16
|
||||
local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE, getter=GETTER+PROPERTY, setter=SETTER+PROPERTY}
|
||||
local MODIFIER_MASK, PROPERTY_MASK = {private=MUTABLE+GETTER+SETTER, public=MUTABLE+GETTER+SETTER, mutable=PRIVATE+PUBLIC, getter=PRIVATE+PUBLIC, setter=PRIVATE+PUBLIC}, PRIVATE+PUBLIC
|
||||
local PRIVATE, PUBLIC, MUTABLE, PROPERTY, ACCESSOR, MUTATOR = 0, 1, 2, 4, 8, 16
|
||||
local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE, accessor=ACCESSOR+PROPERTY, mutator=MUTATOR+PROPERTY}
|
||||
local MODIFIER_MASK, PROPERTY_MASK = {private=MUTABLE+ACCESSOR+MUTATOR, public=MUTABLE+ACCESSOR+MUTATOR, mutable=PRIVATE+PUBLIC, accessor=PRIVATE+PUBLIC, mutator=PRIVATE+PUBLIC}, PRIVATE+PUBLIC
|
||||
local error, declaration_error, immutable_error, collision_error, void_error, set_property, lock_mt, env_mt, interface_mt, declarator_mt, importer_mt
|
||||
lock_mt = {}
|
||||
local _state, _modules = {}, setmetatable({}, lock_mt)
|
||||
@@ -21,7 +21,7 @@ function importer_mt.__call(self, arg1, arg2)
|
||||
if alias == '_' then
|
||||
for key, modifiers in module.metadata do
|
||||
if not state.metadata[key] and mask(PUBLIC, modifiers) ~= 0 then
|
||||
state.metadata[key], state.data[key], state.getters[key], state.setters[key] = modifiers, module.data[key], module.getters[key], module.setters[key]
|
||||
state.metadata[key], state.data[key], state.accessors[key], state.mutators[key] = modifiers, module.data[key], module.accessors[key], module.mutators[key]
|
||||
end
|
||||
end
|
||||
elseif not state.metadata[alias] then
|
||||
@@ -53,7 +53,7 @@ function declarator_mt.__newindex(self, key, value)
|
||||
if mask(PROPERTY, state.modifiers) == 0 then
|
||||
state.data[key] = value
|
||||
elseif type(value) == 'function' or declaration_error(2) then
|
||||
local data = mask(GETTER, state.modifiers) ~= 0 and state.getters or state.setters
|
||||
local data = mask(ACCESSOR, state.modifiers) ~= 0 and state.accessors or state.mutators
|
||||
state.property, data[key] = key, value
|
||||
end
|
||||
state.modifiers = PRIVATE
|
||||
@@ -66,8 +66,8 @@ do
|
||||
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] or void_error(key, 2) end
|
||||
local accessor = state.accessors[key]
|
||||
if accessor then return accessor() else return default[key] or void_error(key, 2) end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -75,8 +75,8 @@ do
|
||||
function env_mt.__newindex(self, key, value)
|
||||
local state = _state[self]; local modifiers = state.metadata[key]
|
||||
if modifiers then
|
||||
local setter = state.setters[key]
|
||||
if setter then return setter(value) end
|
||||
local mutator = state.mutators[key]
|
||||
if mutator then return mutator(value) end
|
||||
if mask(MUTABLE, modifiers) == 0 then immutable_error(key, 2) end
|
||||
else
|
||||
state.metadata[key] = state.modifiers
|
||||
@@ -86,8 +86,8 @@ do
|
||||
interface_mt = {__metatable=false, __index=index(PUBLIC, {})}
|
||||
function interface_mt.__newindex(self, key, value)
|
||||
local state = _state[self]; local metadata = state.metadata or void_error(key, 2)
|
||||
if mask(PUBLIC+SETTER, metadata) == PUBLIC+SETTER then
|
||||
return state.setters[key](value)
|
||||
if mask(PUBLIC+MUTATOR, metadata) == PUBLIC+MUTATOR then
|
||||
return state.mutators[key](value)
|
||||
elseif mask(PUBLIC, metadata) == PUBLIC or immutable_error(key, 2) then
|
||||
state.data[key] = value
|
||||
end
|
||||
@@ -96,17 +96,17 @@ end
|
||||
function INIT() end
|
||||
function module(name)
|
||||
if not _modules[name] then
|
||||
local state, getters, setters, env, interface, declarator, importer
|
||||
local state, accessors, mutators, env, interface, declarator, importer
|
||||
env, interface, declarator, importer = setmetatable({}, env_mt), setmetatable({}, interface_mt), setmetatable({}, declarator_mt), setmetatable({}, importer_mt)
|
||||
getters = {
|
||||
accessors = {
|
||||
private=function() state.modifiers = PRIVATE return declarator end, public=function() state.modifiers = PUBLIC return declarator end,
|
||||
mutable=function() state.modifiers = MUTABLE return declarator end,
|
||||
getter=function() state.modifiers = PROPERTY+GETTER return declarator end, setter=function() state.modifiers = PROPERTY+SETTER return declarator end}
|
||||
setters = {getter=function(value) set_property(getters, state.property, value) end, setter=function(value) set_property(setters, state.property, value) end}
|
||||
accessor=function() state.modifiers = PROPERTY+ACCESSOR return declarator end, mutator=function() state.modifiers = PROPERTY+MUTATOR return declarator end}
|
||||
mutators = {accessor=function(value) set_property(accessors, state.property, value) end, mutator=function(value) set_property(mutators, state.property, value) end}
|
||||
state = {
|
||||
env=env, interface=interface, modifiers=PRIVATE,
|
||||
metadata = setmetatable({_g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=PROPERTY+GETTER, public=PROPERTY+GETTER, mutable=PROPERTY+GETTER, getter=PROPERTY+GETTER+SETTER, setter=PROPERTY+GETTER+SETTER}, lock_mt),
|
||||
data = {_g=_g, _m=env, _i=interface, import=importer}, getters=getters, setters=setters,
|
||||
metadata = setmetatable({_g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=PROPERTY+ACCESSOR, public=PROPERTY+ACCESSOR, mutable=PROPERTY+ACCESSOR, accessor=PROPERTY+ACCESSOR+MUTATOR, mutator=PROPERTY+ACCESSOR+MUTATOR}, lock_mt),
|
||||
data = {_g=_g, _m=env, _i=interface, import=importer}, accessors=accessors, mutators=mutators,
|
||||
}
|
||||
_modules[name], _state[env], _state[interface], _state[declarator], _state[importer] = state, state, state, state, state
|
||||
setfenv(INIT, env); INIT()
|
||||
|
||||
@@ -9,7 +9,7 @@ do
|
||||
local searches = {}
|
||||
local search_index = 1
|
||||
|
||||
function getter.current_search() return searches[search_index] end
|
||||
function accessor.current_search() return searches[search_index] end
|
||||
|
||||
function update_search(index)
|
||||
searches[search_index].status_bar:Hide()
|
||||
|
||||
+5
-5
@@ -15,15 +15,15 @@ end
|
||||
|
||||
do
|
||||
local value, charges
|
||||
local function setter(n)
|
||||
local function mutator(n)
|
||||
return function(v)
|
||||
assert(charges == 0)
|
||||
value, charges = v, n
|
||||
return v
|
||||
end
|
||||
end
|
||||
for i=1,9 do public[join{replicate(i, 'x')}] = setter(i) end
|
||||
function public.getter.__()
|
||||
for i=1,9 do public[join{replicate(i, 'x')}] = mutator(i) end
|
||||
function public.accessor.__()
|
||||
assert(charges > 0)
|
||||
charges = charges - 1
|
||||
return value
|
||||
@@ -85,7 +85,7 @@ end
|
||||
|
||||
public.huge = 1.8*10^308
|
||||
|
||||
function public.getter.modified() return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() end
|
||||
function public.accessor.modified() return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() end
|
||||
|
||||
--do TODO
|
||||
-- local _state = setmetatable({}, {__mode='kv'})
|
||||
@@ -233,7 +233,7 @@ end
|
||||
|
||||
function public.round(x) return floor(x + 0.5) end
|
||||
|
||||
function public.getter.inventory()
|
||||
function public.accessor.inventory()
|
||||
local bag, slot = 0, 0
|
||||
return function()
|
||||
if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then
|
||||
|
||||
+2
-2
@@ -267,10 +267,10 @@ function public.auctionable(tooltip, quality, lootable)
|
||||
and not (durability and durability < max_durability)
|
||||
end
|
||||
|
||||
function public.tooltip(setter)
|
||||
function public.tooltip(mutator)
|
||||
AuxTooltip:SetOwner(UIParent, 'ANCHOR_NONE')
|
||||
AuxTooltip.money = 0
|
||||
setter(AuxTooltip)
|
||||
mutator(AuxTooltip)
|
||||
AuxTooltip:Show()
|
||||
|
||||
local tooltip = {}
|
||||
|
||||
@@ -10,7 +10,7 @@ do
|
||||
realm = GetCVar 'realmName'
|
||||
end
|
||||
|
||||
function getter.dataset_key() return realm..'|'..faction end
|
||||
function accessor.dataset_key() return realm..'|'..faction end
|
||||
end
|
||||
|
||||
function public.load_dataset()
|
||||
@@ -26,7 +26,7 @@ end
|
||||
-- end,
|
||||
-- __call = function(self, field) end
|
||||
-- }
|
||||
-- function public.getter.record()
|
||||
-- function public.accessor.record()
|
||||
--
|
||||
-- end
|
||||
--end
|
||||
|
||||
Reference in New Issue
Block a user