From 9adbe7f2ca0efba8ea1608bffc18f4b28782426f Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Thu, 25 Aug 2016 01:32:55 +0200 Subject: [PATCH] refactoring --- aux-addon.lua | 57 +++++++++++++++++++++++------------------ control.lua | 11 +++++--- core/history.lua | 6 ++--- core/scan.lua | 4 +-- gui/core.lua | 2 +- tabs/post/core.lua | 4 +-- tabs/search/results.lua | 2 +- util/color.lua | 4 +-- util/core.lua | 2 +- util/info.lua | 2 +- util/persistence.lua | 2 +- 11 files changed, 53 insertions(+), 43 deletions(-) diff --git a/aux-addon.lua b/aux-addon.lua index ed1ec16..86d697c 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -3,18 +3,19 @@ public.version = '5.0.0' do local bids_loaded - public.property.bids_loaded{ + public.bids_loaded + { get = function() return bids_loaded end, set = function(value) bids_loaded = value end, } --- function public.bids_loaded.get() --- end end do local current_owner_page - public.current_owner_page() - function accessor() return current_owner_page end - function mutator(value) current_owner_page = value end + public.current_owner_page + { + get = function() return current_owner_page end, + set = function(value) current_owner_page = value end, + } end public.empty = {} @@ -41,10 +42,10 @@ do end log(getn(table_pool), '-', getn(overflow_pool)) end - function public.accessor.t() + function public.t.get() return tremove(pool) or tremove(overflow_pool) or {} end - function public.accessor.tt() + function public.tt.get() local t = tremove(pool) or tremove(overflow_pool) or {} transient[t] = true return t @@ -63,10 +64,16 @@ do function make_persistent(t) transient[t] = nil return t end temp_mt = operator_mt(make_transient) perm_mt = operator_mt(make_persistent) - function public.accessor.temp() return setmetatable(t, temp_mt) end - function mutator(t) return make_transient(t) end - function public.accessor.perm() return setmetatable(t, perm_mt) end - function mutator(t) return make_persistent(t) end + public.temp + { + get = function() return setmetatable(t, temp_mt) end, + set = function(t) return make_transient(t) end, + } + public.perm + { + get = function() return setmetatable(t, perm_mt) end, + set = function(t) return make_persistent(t) end, + } end local function keys(t,k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15,k16,k17,k18,k19,k20,overflow) if overflow ~= nil then error 'Overflow.' end @@ -137,9 +144,9 @@ do -- public.accessor() -- set, list, object = function() return setmetatable(t, set_mt) end, function() return setmetatable(t, list_mt) end, function() return setmetatable(t, object_mt) end -- private() - function public.accessor.set() return setmetatable(t, set_mt) end - function public.accessor.list() return setmetatable(t, list_mt) end - function public.accessor.object() return setmetatable(t, object_mt) end + function public.set.get() return setmetatable(t, set_mt) end + function public.list.get() return setmetatable(t, list_mt) end + function public.object.get() return setmetatable(t, object_mt) end -- TODO or 'auto' 'transient'? end @@ -151,8 +158,8 @@ end ADDON_LOADED = t do local handlers, handlers2 = t, t - function public.mutator.LOAD(f) tinsert(handlers, f) end - function public.mutator.LOAD2(f) tinsert(handlers2, f) end + function public.LOAD.set(f) tinsert(handlers, f) end + function public.LOAD2.set(f) tinsert(handlers2, f) end event_frame:SetScript('OnEvent', function() if event == 'ADDON_LOADED' then if ADDON_LOADED[arg1] then ADDON_LOADED[arg1]() end @@ -182,18 +189,18 @@ do log(data[i], data[i + 1]) local tab = -object('name', data[i + 1]) local env = (function() module(data[i]) return M end)() - function env.mutator.OPEN(f) tab.OPEN = f end - function env.mutator.CLOSE(f) tab.CLOSE = f end - function env.mutator.USE_ITEM(f) tab.USE_ITEM = f end - function env.mutator.CLICK_LINK(f) tab.CLICK_LINK = f end - function env.public.accessor.ACTIVE() return tab == active_tab end + function env.OPEN.set(f) tab.OPEN = f end + function env.CLOSE.set(f) tab.CLOSE = f end + function env.USE_ITEM.set(f) tab.USE_ITEM = f end + function env.CLICK_LINK.set(f) tab.CLICK_LINK = f end + function env.public.ACTIVE.get() return tab == active_tab end tinsert(tab_info, tab) end end do local active_tab_index - function accessor.active_tab() return tab_info[active_tab_index] end + function property.active_tab.get() return tab_info[active_tab_index] end function on_tab_click(index) call(active_tab_index and active_tab.CLOSE) active_tab_index = index @@ -236,7 +243,7 @@ end do local locked - function public.accessor.bid_in_progress() 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 local money = GetMoney() @@ -256,7 +263,7 @@ end do local locked - function public.accessor.cancel_in_progress() return locked end + function public.cancel_in_progress.get() return locked end function public.cancel_auction(index, on_success) if locked then return end locked = true diff --git a/control.lua b/control.lua index 1f49c43..90e5355 100644 --- a/control.lua +++ b/control.lua @@ -6,9 +6,12 @@ mutable.threads = t do local thread_id - public.thread_id() - function accessor() return thread_id end - function mutator(value) thread_id = value end + public.thread_id + { + get = function() return thread_id end, + set = function(value) thread_id = value end, + } + end function LOAD() @@ -50,7 +53,7 @@ end do local id = 0 - function accessor.id() id = id + 1; return id end + function property.id.get() id = id + 1; return id end end function public.kill_listener(listener_id) diff --git a/core/history.lua b/core/history.lua index cc0a3c6..751c666 100644 --- a/core/history.lua +++ b/core/history.lua @@ -12,7 +12,7 @@ value_cache = t do local data - function accessor.data() + function property.data.get() if not data then local dataset = persistence.dataset data = dataset.history or t @@ -24,7 +24,7 @@ end do local next_push = 0 - function accessor.next_push() + function property.next_push.get() if time() > next_push then local date = date '*t' date.hour, date.min, date.sec = 24, 0, 0 @@ -34,7 +34,7 @@ do end end -function accessor.new_record() +function property.new_record.get() return -object('next_push', next_push, 'data_points', t) end diff --git a/core/scan.lua b/core/scan.lua index a55d507..26ad141 100644 --- a/core/scan.lua +++ b/core/scan.lua @@ -41,13 +41,13 @@ do call(on_complete) end - function accessor.state() + function property.state.get() local _, state = next(filter(scan_states, function(state) return state.id == thread_id end)) return state end end -function accessor.query() return state.params.queries[state.query_index] end +function property.query.get() return state.params.queries[state.query_index] end function wait_for_callback(...) temp=arg local send_signal, signal_received = signal() diff --git a/gui/core.lua b/gui/core.lua index 0a60d68..63d34d5 100644 --- a/gui/core.lua +++ b/gui/core.lua @@ -88,7 +88,7 @@ public.font_size = { do local id = 1 - function public.accessor.name() + function public.name.get() id = id + 1 return 'aux_frame'..id end diff --git a/tabs/post/core.lua b/tabs/post/core.lua index 3201241..cf9cca2 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -3,13 +3,13 @@ module 'post_tab' import 'scan' 'scan_util' 'post' 'history' 'info' 'persistence local DURATION_4, DURATION_8, DURATION_24 = 120, 480, 1440 local settings_schema = {'record', '#', {stack_size='number'}, {duration='number'}, {start_price='number'}, {buyout_price='number'}, {hidden='boolean'}} -function accessor.default_settings() +function property.default_settings.get() return -object('duration', DURATION_8 , 'stack_size', 1, 'start_price', 0, 'buyout_price', 0, 'hidden', false) end do local data - function accessor.data() + function property.data.get() if not data then local dataset = persistence.dataset data = dataset.post or t diff --git a/tabs/search/results.lua b/tabs/search/results.lua index 00e5726..f89530f 100644 --- a/tabs/search/results.lua +++ b/tabs/search/results.lua @@ -9,7 +9,7 @@ do local searches = t local search_index = 1 - function accessor.current_search() return searches[search_index] end + function current_search.get() return searches[search_index] end function update_search(index) searches[search_index].status_bar:Hide() diff --git a/util/color.lua b/util/color.lua index 9c35511..ae68ea0 100644 --- a/util/color.lua +++ b/util/color.lua @@ -49,13 +49,13 @@ do end end } - public.accessor.color = color_accessor(function(color) + 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) +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) diff --git a/util/core.lua b/util/core.lua index 4dca507..5e4c68f 100644 --- a/util/core.lua +++ b/util/core.lua @@ -66,7 +66,7 @@ end public.huge = 1.8*10^308 -function public.accessor.modified() 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'}) diff --git a/util/info.lua b/util/info.lua index 428bca1..6741d80 100644 --- a/util/info.lua +++ b/util/info.lua @@ -403,7 +403,7 @@ function public.item_quality_index(item_quality) end end -function public.accessor.inventory() +function public.inventory.get() local bag, slot = 0, 0 return function() if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then diff --git a/util/persistence.lua b/util/persistence.lua index 947d6de..d611e15 100644 --- a/util/persistence.lua +++ b/util/persistence.lua @@ -4,7 +4,7 @@ _G.aux_datasets = t do local dataset - function public.accessor.dataset() + function public.dataset.get() if not dataset then local dataset_key = format('%s|%s', GetCVar 'realmName', UnitFactionGroup 'player') dataset = _G.aux_datasets[dataset_key] or t