diff --git a/components/cache.lua b/components/cache.lua index 6e530fc..ebc75ca 100644 --- a/components/cache.lua +++ b/components/cache.lua @@ -1,10 +1,10 @@ -aux.module 'cache' +module 'cache' MIN_ITEM_ID = 1 MAX_ITEM_ID = 30000 items_schema = {'record', '#', {name='string'}, {quality='number'}, {level='number'}, {class='string'}, {subclass='string'}, {slot='string'}, {max_stack='number'}, {texture='string'}} -merchant_buy_schema = {'record', '#', {unit_price='number'}, {limited='boolean'} } +merchant_buy_schema = {'record', '#', {unit_price='number'}, {limited='boolean'}} _g.aux_items = {} _g.aux_item_ids = {} @@ -24,8 +24,8 @@ function LOAD() CreateFrame('Frame', nil, MerchantFrame):SetScript('OnUpdate', merchant_on_update) control.event_listener('NEW_AUCTION_UPDATE', function() - for _, info in {info.auction_sell_item()} do - for _, item_id in {cache.item_id(info.name)} do + for info in present(info.auction_sell_item()) do + for item_id in present(cache.item_id(info.name)) do _g.aux_merchant_sell[cache.item_id(info.name)] = info.vendor_price / (info.max_item_charges(item_id) or info.count) end end @@ -128,12 +128,12 @@ function merchant_buy_scan() unit_price = min(buy_info.unit_price, new_unit_price) end - _g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, { + g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, { unit_price = unit_price, limited = buy_info.limited and new_limited, }) else - _g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, { + g.aux_merchant_buy[item_id] = persistence.write(merchant_buy_schema, { unit_price = new_unit_price, limited = new_limited, }) @@ -150,7 +150,7 @@ function merchant_sell_scan() for slot in inventory do local item_info = info.container_item(unpack(slot)) if item_info then - _g.aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity + g.aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity end end end @@ -162,9 +162,9 @@ function scan_wdb(item_id) while processed <= 100 and item_id <= MAX_ITEM_ID do local itemstring = 'item:'..item_id local name, _, quality, level, class, subclass, max_stack, slot, texture = GetItemInfo(itemstring) - if name and not _g.aux_item_ids[strlower(name)] then - _g.aux_item_ids[strlower(name)] = item_id - _g.aux_items[item_id] = persistence.write(items_schema, { + if name and not g.aux_item_ids[strlower(name)] then + g.aux_item_ids[strlower(name)] = item_id + g.aux_items[item_id] = persistence.write(items_schema, { name = name, quality = quality, level = level, @@ -176,7 +176,7 @@ function scan_wdb(item_id) }) local tooltip = info.tooltip(function(tt) tt:SetHyperlink(itemstring) end) if info.auctionable(tooltip, quality) then - tinsert(_g.aux_auctionable_items, strlower(name)) + tinsert(g.aux_auctionable_items, strlower(name)) end processed = processed + 1 end @@ -187,7 +187,7 @@ function scan_wdb(item_id) local t0 = GetTime() control.thread(control.when, function() return GetTime() - t0 > 0.1 end, scan_wdb, item_id) else - sort(_g.aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end) + sort(g.aux_auctionable_items, function(a, b) return strlen(a) < strlen(b) or (strlen(a) == strlen(b) and a < b) end) end end diff --git a/components/disenchant.lua b/components/disenchant.lua index bf31601..464cb57 100644 --- a/components/disenchant.lua +++ b/components/disenchant.lua @@ -1,4 +1,4 @@ -aux.module 'disenchant' +module 'disenchant' UNCOMMON = 2 RARE = 3 diff --git a/components/history.lua b/components/history.lua index 27f2305..b836dd6 100644 --- a/components/history.lua +++ b/components/history.lua @@ -1,4 +1,4 @@ -aux.module 'history' +module 'history' local history_schema = {'record', '#', {next_push='number'}, {daily_min_buyout='number'}, {daily_max_price='number'}, {data_points={'list', ';', {'record', '@', {market_value='number'}, {time='number'}}}}} value_cache = {} diff --git a/components/post.lua b/components/post.lua index ee506fc..f718cbf 100644 --- a/components/post.lua +++ b/components/post.lua @@ -1,4 +1,4 @@ -aux.module 'post' +module 'post' state = nil diff --git a/components/scan.lua b/components/scan.lua index c98a6ed..41c1de3 100644 --- a/components/scan.lua +++ b/components/scan.lua @@ -1,4 +1,4 @@ -aux.module 'scan' +module 'scan' PAGE_SIZE = 50 diff --git a/components/stack.lua b/components/stack.lua index b243474..9d21cfb 100644 --- a/components/stack.lua +++ b/components/stack.lua @@ -1,4 +1,4 @@ -aux.module 'stack' +module 'stack' state = nil diff --git a/components/tooltip.lua b/components/tooltip.lua index 03a2e11..a460c8f 100644 --- a/components/tooltip.lua +++ b/components/tooltip.lua @@ -1,4 +1,5 @@ -aux.module 'tooltip' +module 'tooltip' +import 'gui' 'lol' 'kek' _g.aux_tooltip_value = true @@ -206,15 +207,11 @@ end function game_tooltip_hooks:SetCraftItem(skill, slot) local link, quantity if slot then - link = GetCraftReagentItemLink(skill, slot) - quantity = ({GetCraftReagentInfo(skill, slot)})[3] + link, quantity = GetCraftReagentItemLink(skill, slot), select(3, GetCraftReagentInfo(skill, slot)) else - link = GetCraftItemLink(skill) - quantity = 1 - end - if link then - extend_tooltip(GameTooltip, link, quantity) + link, quantity = GetCraftItemLink(skill), 1 end + if link then extend_tooltip(GameTooltip, link, quantity) end end function game_tooltip_hooks:SetCraftSpell(slot) diff --git a/control.lua b/control.lua index 0a8df1e..87b478a 100644 --- a/control.lua +++ b/control.lua @@ -1,4 +1,4 @@ -aux.module 'control' +module 'control' event_frame = CreateFrame 'Frame' listeners = {} diff --git a/core.lua b/core.lua index e74103a..d47d5f3 100644 --- a/core.lua +++ b/core.lua @@ -1,4 +1,4 @@ -aux.module 'core' +module 'core' public.bids_loaded = false public.current_owner_page = nil diff --git a/gui.lua b/gui.lua index 03f8435..78fef9b 100644 --- a/gui.lua +++ b/gui.lua @@ -1,4 +1,4 @@ -aux.module 'gui' +module 'gui' public.config = { colors = { diff --git a/init.lua b/init.lua index 9f90e43..2b9ae93 100644 --- a/init.lua +++ b/init.lua @@ -1,43 +1,33 @@ -local aux_module, setn, tinsert, tremove, setfenv = aux_module, table.setn, tinsert, tremove, setfenv -local aux = aux_module 'core' -_g.aux = aux.interface +ADDON = aux +function INIT() + import{['']='modules', ['']='core', ['']='util'} +end + +module 'core' -- .interface {x = 'core'} {y='core'} 'kek' public.version = '5.0.0' do local table_pool, auto_recycle = {}, {} - local function wipe(t) -- like with a cloth or something - for k in t do t[k] = nil end - setn(t, 0); return t + function public.wipe(t) -- like with a cloth or something + for k in t do t[k] = nil end; setn(t, 0) end function public.recycle(t) - auto_recycle[t] = nil - tinsert(table_pool, wipe(t)) --- log(getn(table_pool)) + auto_recycle[t] = nil; wipe(t); tinsert(table_pool, t) end public.temp = setmetatable({}, {__sub = function(_, t) auto_recycle[t] = true return t 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 + CreateFrame 'Frame' :SetScript('OnUpdate', function() + for t in auto_recycle do recycle(t); log(getn(table_pool)) end + wipe(auto_recycle) end) end -do - local modules = {} - local function module_env(name) aux_module(name) return _m end - function public.module(name) - local env = module_env(name) - if not modules[name] then env.import(temp-{['']='modules', ['']='core', ['']='util'}) end - setfenv(2, env); modules[name] = true - end -end - local event_frame = CreateFrame 'Frame' 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) end -ADDON_LOADED = {} +ADDON_LOADED = t do local variables_loaded_hooks, player_login_hooks = t, t function public.setter.LOAD(f) tinsert(variables_loaded_hooks, f) end diff --git a/module.lua b/module.lua index 449d67c..19e04f6 100644 --- a/module.lua +++ b/module.lua @@ -1,4 +1,5 @@ -local type, setmetatable, setfenv, unpack, mask, _g = type, setmetatable, setfenv, unpack, bit.band, getfenv(0) +local _g = getfenv(); setfenv(0, setmetatable({}, {__index = function(_, key) return key end})) +local type, setmetatable, setfenv, unpack, mask = _g.type, _g.setmetatable, _g.setfenv, _g.unpack, _g.bit.band, _g.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 @@ -74,7 +75,8 @@ do end end end -function _g.aux_module(name) +function INIT() end +function module(name) if not _modules[name] then local state, getters, setters, imports, env, interface, declarator imports, env, interface, declarator = {}, setmetatable({}, env_mt), setmetatable({}, interface_mt), setmetatable({}, declarator_mt) @@ -84,21 +86,22 @@ function _g.aux_module(name) 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} state = { - name=name, env=env, interface=interface, imports={}, declarator_state=PRIVATE, + name=name, env=env, interface=interface, imports={}, 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=function(t) import(imports, t) end}, getters=getters, setters=setters, } _modules[name], _state[env], _state[interface], _state[declarator] = state, state, state, state + setfenv(INIT, env); INIT() end local module = _modules[name] setfenv(2, module.env) return module end local frame = CreateFrame 'Frame' -frame:RegisterEvent 'PLAYER_LOGIN' +frame:RegisterEvent 'ADDON_LOADED' frame:SetScript('OnEvent', function() - lock_mt.__newindex = function() error 'Modules are frozen after the loading phase.' end + if arg1 ~= ADDON then return end local count = 0 local t0 = GetTime() for _, module in _modules do @@ -119,5 +122,7 @@ frame:SetScript('OnEvent', function() end end end - _g.aux.log('imported: '..count..' in '..(GetTime()-t0)) + aux.log('imported: '..count..' in '..(GetTime()-t0)) + lock_mt.__newindex = function() error 'Modules are frozen after the loading phase.' end + setfenv(0, _g) end) \ No newline at end of file diff --git a/tables/auction_listing.lua b/tables/auction_listing.lua index a726c8c..629f9ce 100644 --- a/tables/auction_listing.lua +++ b/tables/auction_listing.lua @@ -1,4 +1,4 @@ -aux.module 'auction_listing' +module 'auction_listing' _g.aux_price_per_unit = false diff --git a/tables/item_listing.lua b/tables/item_listing.lua index 26edeaa..043af10 100644 --- a/tables/item_listing.lua +++ b/tables/item_listing.lua @@ -1,4 +1,4 @@ -aux.module 'item_listing' +module 'item_listing' local ROW_HEIGHT = 39 diff --git a/tables/listing.lua b/tables/listing.lua index 88f7fd0..0db9ee2 100644 --- a/tables/listing.lua +++ b/tables/listing.lua @@ -1,4 +1,4 @@ -aux.module 'listing' +module 'listing' local ST_COUNT = 0 diff --git a/tabs/auctions/core.lua b/tabs/auctions/core.lua index 2e59108..9b4fe85 100644 --- a/tabs/auctions/core.lua +++ b/tabs/auctions/core.lua @@ -1,4 +1,4 @@ -aux.module 'auctions_tab' +module 'auctions_tab' aux.tab(3, 'Auctions') auction_records = nil diff --git a/tabs/auctions/frames.lua b/tabs/auctions/frames.lua index 8566e28..b5b30a2 100644 --- a/tabs/auctions/frames.lua +++ b/tabs/auctions/frames.lua @@ -1,4 +1,4 @@ -aux.module 'auctions_tab' +module 'auctions_tab' function create_frames() frame = CreateFrame('Frame', nil, frame) diff --git a/tabs/bids/core.lua b/tabs/bids/core.lua index 1781e3e..ae445cc 100644 --- a/tabs/bids/core.lua +++ b/tabs/bids/core.lua @@ -1,4 +1,4 @@ -aux.module 'bids_tab' +module 'bids_tab' aux.tab(4, 'Bids') auction_records = nil diff --git a/tabs/bids/frames.lua b/tabs/bids/frames.lua index 40d58d2..2f51b0a 100644 --- a/tabs/bids/frames.lua +++ b/tabs/bids/frames.lua @@ -1,4 +1,4 @@ -aux.module 'bids_tab' +module 'bids_tab' function create_frames() frame = CreateFrame('Frame', nil, frame) diff --git a/tabs/post/core.lua b/tabs/post/core.lua index 8b28da8..aa6d668 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -1,4 +1,4 @@ -aux.module 'post_tab' +module 'post_tab' aux.tab(2, 'Post') local DURATION_4, DURATION_8, DURATION_24 = 120, 480, 1440 diff --git a/tabs/post/frames.lua b/tabs/post/frames.lua index 86ae259..dae97d1 100644 --- a/tabs/post/frames.lua +++ b/tabs/post/frames.lua @@ -1,4 +1,4 @@ -aux.module 'post_tab' +module 'post_tab' function create_frames() frame = CreateFrame('Frame', nil, frame) diff --git a/tabs/search/core.lua b/tabs/search/core.lua index 5ac5065..259a2a2 100644 --- a/tabs/search/core.lua +++ b/tabs/search/core.lua @@ -1,4 +1,4 @@ -aux.module 'search_tab' +module 'search_tab' aux.tab(1, 'Search') StaticPopupDialogs['AUX_SEARCH_TABLE_FULL'] = { diff --git a/tabs/search/filter.lua b/tabs/search/filter.lua index a4ded42..7ca0f03 100644 --- a/tabs/search/filter.lua +++ b/tabs/search/filter.lua @@ -1,4 +1,4 @@ -aux.module 'search_tab' +module 'search_tab' function valid_level(str) local level = tonumber(str) diff --git a/tabs/search/frames.lua b/tabs/search/frames.lua index 8e0ffd0..8d1dc20 100644 --- a/tabs/search/frames.lua +++ b/tabs/search/frames.lua @@ -1,4 +1,4 @@ -aux.module 'search_tab' +module 'search_tab' FILTER_SPACING = 28.5 diff --git a/tabs/search/results.lua b/tabs/search/results.lua index 4e6ad87..6718b90 100644 --- a/tabs/search/results.lua +++ b/tabs/search/results.lua @@ -1,4 +1,4 @@ -aux.module 'search_tab' +module 'search_tab' _g.aux_auto_buy_filter = '' diff --git a/tabs/search/saved.lua b/tabs/search/saved.lua index b73c3a1..43fa89c 100644 --- a/tabs/search/saved.lua +++ b/tabs/search/saved.lua @@ -1,4 +1,4 @@ -aux.module 'search_tab' +module 'search_tab' _g.aux_favorite_searches = {} _g.aux_recent_searches = {} diff --git a/util/completion.lua b/util/completion.lua index c63cdb2..0d426e7 100644 --- a/util/completion.lua +++ b/util/completion.lua @@ -1,4 +1,4 @@ -aux.module 'completion' +module 'completion' function public:complete_filter() if IsControlKeyDown() then -- TODO problem is ctrl-v, maybe find a better solution diff --git a/util/core.lua b/util/core.lua index 5e5bcaf..7017421 100644 --- a/util/core.lua +++ b/util/core.lua @@ -1,6 +1,4 @@ -aux.module 'util' - -local temp, recycle, getn = _g.aux.temp, _g.aux.recycle, _g.getn +module 'util' function public.copy(t) local copy = {} diff --git a/util/filter.lua b/util/filter.lua index 7bdaf51..0f996c0 100644 --- a/util/filter.lua +++ b/util/filter.lua @@ -1,4 +1,4 @@ -aux.module 'filter' +module 'filter' function default_filter(str) return { diff --git a/util/info.lua b/util/info.lua index c4150ea..9628554 100644 --- a/util/info.lua +++ b/util/info.lua @@ -1,4 +1,4 @@ -aux.module 'info' +module 'info' CreateFrame('GameTooltip', 'AuxTooltip', nil, 'GameTooltipTemplate') AuxTooltip:SetScript('OnTooltipAddMoney', function() diff --git a/util/money.lua b/util/money.lua index 1a9e05f..6dad09c 100644 --- a/util/money.lua +++ b/util/money.lua @@ -1,4 +1,4 @@ -aux.module 'money' +module 'money' GOLD_TEXT = '|cffffd70ag|r' SILVER_TEXT = '|cffc7c7cfs|r' diff --git a/util/persistence.lua b/util/persistence.lua index 5ab72d9..8a9c4ca 100644 --- a/util/persistence.lua +++ b/util/persistence.lua @@ -1,4 +1,4 @@ -aux.module 'persistence' +module 'persistence' _g.aux_datasets = {} @@ -19,6 +19,18 @@ function public.load_dataset() return _g.aux_datasets[dataset_key] end +--do TODO syntactic sugar +-- local mt = { +-- __unm = function(self, separator) +-- self.separator = separator +-- end, +-- __call = function(self, field) end +-- } +-- function public.getter.record() +-- +-- end +--end + function public.read(schema, str) if schema == 'string' then return str diff --git a/util/scan_util.lua b/util/scan_util.lua index e5218f1..7622ac2 100644 --- a/util/scan_util.lua +++ b/util/scan_util.lua @@ -1,4 +1,4 @@ -aux.module 'scan_util' +module 'scan_util' function public.find(auction_record, status_bar, on_abort, on_failure, on_success) diff --git a/util/sort.lua b/util/sort.lua index fe18f4e..9eebe66 100644 --- a/util/sort.lua +++ b/util/sort.lua @@ -1,4 +1,4 @@ -aux.module 'sorting' +module 'sorting' public.LT = {} public.EQ = {}