big refactoring
This commit is contained in:
+5
-7
@@ -37,15 +37,13 @@ do
|
||||
call(on_complete)
|
||||
end
|
||||
|
||||
private.state{
|
||||
get = function()
|
||||
local _, state = next(filter(scan_states, function(state) return state.id == control.thread_id end))
|
||||
return state
|
||||
end,
|
||||
}
|
||||
function private.state.get()
|
||||
local _, state = next(filter(scan_states, function(state) return state.id == control.thread_id end))
|
||||
return state
|
||||
end
|
||||
end
|
||||
|
||||
private.query{get=function() return state.params.queries[state.query_index] end}
|
||||
function private.query.get() 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
|
||||
private.id{get=function() id = id + 1; return id end}
|
||||
function private.id.get() id = id + 1; return id end
|
||||
end
|
||||
|
||||
function public.kill_listener(listener_id)
|
||||
|
||||
@@ -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.ACTIVE{get=function() return tab == active_tab end}
|
||||
function module_env.public.ACTIVE.get() 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
|
||||
private.active_tab{get=function() return tabs[active_tab_index] end}
|
||||
function private.active_tab.get() 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,11 +88,9 @@ end
|
||||
|
||||
do
|
||||
local locked
|
||||
public.bid_in_progress{get=function() return locked end}
|
||||
function public.bid_in_progress.get() return locked end
|
||||
function public.place_bid(type, index, amount, on_success)
|
||||
if locked then
|
||||
return
|
||||
end
|
||||
if locked then return end
|
||||
local money = GetMoney()
|
||||
PlaceAuctionBid(type, index, amount)
|
||||
if money >= amount then
|
||||
@@ -110,11 +108,9 @@ end
|
||||
|
||||
do
|
||||
local locked
|
||||
public.cancel_in_progress{get=function() return locked end}
|
||||
function public.cancel_in_progress.get() return locked end
|
||||
function public.cancel_auction(index, on_success)
|
||||
if locked then
|
||||
return
|
||||
end
|
||||
if locked then return end
|
||||
locked = true
|
||||
CancelAuction(index)
|
||||
control.event_listener('CHAT_MSG_SYSTEM', function(kill)
|
||||
|
||||
@@ -60,24 +60,20 @@ do
|
||||
end
|
||||
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),
|
||||
}
|
||||
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.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),
|
||||
}
|
||||
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
|
||||
public.name{get=function() id = id + 1; return 'aux_frame'..id end}
|
||||
function public.name.get() id = id + 1; return 'aux_frame'..id end
|
||||
end
|
||||
|
||||
do
|
||||
|
||||
@@ -16,7 +16,7 @@ do
|
||||
-- log(getn(table_pool))
|
||||
end
|
||||
public.temp = setmetatable({}, {__sub = function(_, t) auto_recycle[t] = true return t end})
|
||||
public.t{get=function() return tremove(table_pool) or {} end}
|
||||
function public.t.get() return tremove(table_pool) or {} end
|
||||
CreateFrame('Frame'):SetScript('OnUpdate', function()
|
||||
for t in auto_recycle do recycle(t) end
|
||||
recycle(auto_recycle)
|
||||
@@ -43,8 +43,8 @@ end
|
||||
ADDON_LOADED = {}
|
||||
do
|
||||
local variables_loaded_hooks, player_login_hooks = t, t
|
||||
public.LOAD{set=function(f) tinsert(variables_loaded_hooks, f) end}
|
||||
public.LOAD2{set=function(f) tinsert(player_login_hooks, f) end}
|
||||
function public.LOAD.set(f) tinsert(variables_loaded_hooks, f) end
|
||||
function public.LOAD2.set(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
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@ local MODIFIER_MASK, PROPERTY_MASK = {private=MUTABLE+PROPERTY, public=MUTABLE+P
|
||||
local error, declaration_error, immutable_error, collision_error, void_error, import, define_property, lock_mt, env_mt, interface_mt, declarator_mt, property_mt
|
||||
lock_mt = {}
|
||||
local _state, _modules = {}, setmetatable({}, lock_mt)
|
||||
function error(message, level, ...) _g.error(format(message, unpack(arg))..'\n'..debugstack(3, 5, 0), level + 1) end
|
||||
function error(message, level, ...) _g.error(format(message, unpack(arg))..'\n'..debugstack(3, 5, 0), (level or 1) + 1) end
|
||||
function declaration_error(level) error('Malformed declaration.', level + 1) end
|
||||
function immutable_error(key, level) error('Field "%s" is immutable.', level + 1, key) end
|
||||
function collision_error(key, level) error('Field "%s" already exists.', level + 1, key) end
|
||||
@@ -86,9 +86,9 @@ function _g.aux_module(name)
|
||||
local state, imports, env, interface, declarator, property
|
||||
imports, env, interface, declarator, property = {}, setmetatable({}, env_mt), setmetatable({}, interface_mt), setmetatable({}, declarator_mt), setmetatable({}, property_mt)
|
||||
state = {
|
||||
name = name, env = env, interface = interface, imports = {}, declarator_state = PRIVATE,
|
||||
name=name, env=env, interface=interface, imports={}, declarator_state=PRIVATE,
|
||||
metadata = setmetatable({_g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=PROPERTY, public=PROPERTY, getter=PROPERTY, setter=PROPERTY, mutable=PROPERTY}, lock_mt),
|
||||
data = {_g=_g, _m=env, _i=interface, import=function(t) import(imports, t) end},
|
||||
data = {_g=_g, _m=env, _i=interface, property=property, 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 = {},
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ do
|
||||
local searches = {}
|
||||
local search_index = 1
|
||||
|
||||
private.current_search{get=function() return searches[search_index] end}
|
||||
function private.current_search.get() return searches[search_index] end
|
||||
|
||||
function update_search(index)
|
||||
searches[search_index].status_bar:Hide()
|
||||
|
||||
+17
-21
@@ -25,13 +25,11 @@ do
|
||||
end
|
||||
end
|
||||
for i=1,9 do public[join{replicate(i, 'x')}] = setter(i) end
|
||||
public.__{
|
||||
get = function()
|
||||
assert(charges > 0)
|
||||
charges = charges - 1
|
||||
return value
|
||||
end,
|
||||
}
|
||||
function public.__.get()
|
||||
assert(charges > 0)
|
||||
charges = charges - 1
|
||||
return value
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
@@ -89,7 +87,7 @@ end
|
||||
|
||||
public.huge = 1.8*10^308
|
||||
|
||||
public.modified{get=function() return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() end}
|
||||
function public.modified.get() return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() end
|
||||
|
||||
--do TODO
|
||||
-- local _state = setmetatable({}, {__mode='kv'})
|
||||
@@ -247,20 +245,18 @@ end
|
||||
|
||||
function public.round(x) return floor(x + 0.5) end
|
||||
|
||||
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
|
||||
function public.inventory.get()
|
||||
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
|
||||
end,
|
||||
}
|
||||
if bag <= 4 then return {bag, slot}, bag_type(bag) end
|
||||
end
|
||||
end
|
||||
|
||||
function public.bag_type(bag)
|
||||
if bag == 0 then
|
||||
|
||||
@@ -10,7 +10,7 @@ do
|
||||
realm = GetCVar 'realmName'
|
||||
end
|
||||
|
||||
private.dataset_key{get=function() return realm..'|'..faction end}
|
||||
function private.dataset_key.get() return realm..'|'..faction end
|
||||
end
|
||||
|
||||
function public.load_dataset()
|
||||
|
||||
Reference in New Issue
Block a user