big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-21 21:41:28 +02:00
parent c235f0332e
commit 7232d62418
9 changed files with 30 additions and 32 deletions
+2 -2
View File
@@ -37,13 +37,13 @@ do
call(on_complete)
end
function private.state.get()
function getter.state()
local _, state = next(filter(scan_states, function(state) return state.id == control.thread_id end))
return state
end
end
function private.query.get() return state.params.queries[state.query_index] end
function getter.query() return state.params.queries[state.query_index] end
function wait_for_callback(...)
local send_signal, signal_received = signal()
+1 -1
View File
@@ -44,7 +44,7 @@ end
do
local id = 0
function private.id.get() id = id + 1; return id end
function getter.id() 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}
function module_env.public.ACTIVE.get() return tab == active_tab end
function module_env.public.getter.ACTIVE() 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 private.active_tab.get() return tabs[active_tab_index] end
function getter.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
@@ -88,7 +88,7 @@ end
do
local locked
function public.bid_in_progress.get() return locked end
function public.getter.bid_in_progress() return locked end
function public.place_bid(type, index, amount, on_success)
if locked then return end
local money = GetMoney()
@@ -108,7 +108,7 @@ end
do
local locked
function public.cancel_in_progress.get() return locked end
function public.getter.cancel_in_progress() return locked end
function public.cancel_auction(index, on_success)
if locked then return end
locked = true
+3 -3
View File
@@ -60,20 +60,20 @@ do
end
end
}
public.color.get = color_accessor(function(color)
public.getter.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.inline_color.get = color_accessor(function(color)
public.getter.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.name.get() id = id + 1; return 'aux_frame'..id end
function public.getter.name() id = id + 1; return 'aux_frame'..id end
end
do
+3 -3
View File
@@ -15,7 +15,7 @@ do
-- log(getn(table_pool))
end
public.temp = setmetatable({}, {__sub = function(_, t) auto_recycle[t] = true return t end})
function public.t.get() return tremove(table_pool) or {} end
function public.getter.t() return tremove(table_pool) or {} end
CreateFrame('Frame'):SetScript('OnUpdate', function()
for t in auto_recycle do recycle(t) end
recycle(auto_recycle); auto_recycle = t
@@ -40,8 +40,8 @@ end
ADDON_LOADED = {}
do
local variables_loaded_hooks, player_login_hooks = t, t
function public.LOAD.set(f) tinsert(variables_loaded_hooks, f) end
function public.LOAD2.set(f) tinsert(player_login_hooks, f) end
function public.setter.LOAD(f) tinsert(variables_loaded_hooks, f) end
function public.setter.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
+12 -14
View File
@@ -19,26 +19,24 @@ end
declarator_mt = {__metatable=false}
function declarator_mt.__call() end
function declarator_mt.__index(self, key)
local state, modifier = _state[self], MODIFIER[key]
local state, modifier = _state[self], MODIFIER[key]; local modifiers = state.modifiers
if modifier then
if mask(MODIFIER_MASK[key], state.modifiers) ~= state.modifiers then declaration_error(2) end
state.modifiers = modifier + state.modifiers
return self
if mask(MODIFIER_MASK[key], modifiers) ~= modifiers then declaration_error(2) end
state.modifiers = modifiers + modifier; return self
elseif not state.metadata[key] or collision_error(key, 2) then
if mask(PROPERTY_MASK, state.modifiers) ~= state.modifiers then declaration_error(2) end
state.property, state.metadata[key], state.modifiers = key, PROPERTY + state.modifiers, PRIVATE
if mask(PROPERTY_MASK, modifiers) ~= modifiers then declaration_error(2) end
state.property, state.metadata[key], state.modifiers = key, modifiers + PROPERTY, PRIVATE
end
end
function declarator_mt.__newindex(self, key, value)
local state = _state[self]
if not state.metadata[key] or collision_error(key, 2) then
state.metadata[key] = state.modifiers
if mask(PROPERTY, state.modifiers) == 0 then
state.data[key] = value
elseif type(value) == 'function' or declaration_error(2) then
if mask(GETTER, state.modifiers) ~= 0 then state.getters[key] = value else state.setters[key] = value end
state.property = key
end
if state.metadata[key] then collision_error(key, 2) end
state.metadata[key] = state.modifiers
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
state.property, data[key] = key, value
end
state.modifiers = PRIVATE
end
+1 -1
View File
@@ -9,7 +9,7 @@ do
local searches = {}
local search_index = 1
function private.current_search.get() return searches[search_index] end
function getter.current_search() return searches[search_index] end
function update_search(index)
searches[search_index].status_bar:Hide()
+3 -3
View File
@@ -25,7 +25,7 @@ do
end
end
for i=1,9 do public[join{replicate(i, 'x')}] = setter(i) end
function public.__.get()
function public.getter.__()
assert(charges > 0)
charges = charges - 1
return value
@@ -87,7 +87,7 @@ end
public.huge = 1.8*10^308
function public.modified.get() return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() end
function public.getter.modified() return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() end
--do TODO
-- local _state = setmetatable({}, {__mode='kv'})
@@ -245,7 +245,7 @@ end
function public.round(x) return floor(x + 0.5) end
function public.inventory.get()
function public.getter.inventory()
local bag, slot = 0, 0
return function()
if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then
+1 -1
View File
@@ -10,7 +10,7 @@ do
realm = GetCVar 'realmName'
end
function private.dataset_key.get() return realm..'|'..faction end
function getter.dataset_key() return realm..'|'..faction end
end
function public.load_dataset()