diff --git a/aux-addon.lua b/aux-addon.lua index 651305b..2e86ce4 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -15,48 +15,49 @@ do end do - local table_pool, transient = {}, {} - + local pool, weak_pool, transient = {}, setmetatable({}, {__mode='v'}), {} CreateFrame'Frame':SetScript('OnUpdate', function() - for t in transient do - recycle(t) --- log(getn(table_pool)) - end + for t in transient do recycle(t) end wipe(transient) end) - function public.wipe(t) -- like with a cloth or something - for k in t do - t[k] = nil - end + for k in t do t[k] = nil end table.setn(t, 0) return setmetatable(t, nil) end - function public.recycle(t) transient[t] = nil wipe(t) - tinsert(table_pool, t) + if getn(pool) < 50 then + tinsert(pool, t) + else + tinsert(weak_pool, t) + end + log(getn(table_pool), '-', getn(weak_pool)) end - function public.accessor.t() - return tremove(table_pool) or {} + return tremove(pool) or tremove(weak_pool) or {} end - function public.accessor.tt() - local t = tremove(table_pool) or {} + local t = tremove(pool) or tremove(weak_pool) or {} transient[t] = true return t end - - function public.modifier(f) - local function apply(_, value) return f(value) end - return setmetatable(t, {__call=apply, __sub=apply, __pow=apply, __newindex=function(_, _, value) return f(value) end}) + function public.operator_mt(f) + local function apply(self, value) recycle(self); return self.raw and setmetatable(f(value), nil) or f(value) end + return {__unm=function(self) self.raw = true end, __call=apply, __sub=apply} + end + do + local temp, temp_mt, perm, perm_mt + function temp(t) transient[t] = true return t end + temp_mt = operator_mt(temp) + function perm(t) transient[t] = nil return t end + perm_mt = operator_mt(perm) + function public.accessor.temp() return setmetatable(t, temp_mt) end + function mutator(t) return temp(t) end + function public.accessor.perm() return setmetatable(t, perm_mt) end + function mutator(t) return perm(t) end end - local temp, perm = modifier(function(t) transient[t] = true return t end), modifier(function(t) transient[t] = nil; return t end) - function public.accessor.temp() return temp end; function mutator(t) return temp(t) end - function public.accessor.perm() return perm end; function mutator(t) return perm(t) 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) assert(overflow == nil, 'Overflow.') if k1 ~= nil then t[k1] = true end @@ -123,13 +124,17 @@ do return {__call=f, __unm=function(self) return setmetatable(self, nil) end} end local set_mt, list_mt, object_mt = collector_mt(keys), collector_mt(values), collector_mt(pairs) - - public.accessor.set, public.accessor.list, public.accessor.object = function() return setmetatable(t, set_mt) end, function() return setmetatable(t, list_mt) end, function() return setmetatable(t, object_mt) end +-- 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 -- TODO or 'auto' 'free' 'deprecate' 'release' 'transient'? end local event_frame = CreateFrame 'Frame' -for event in -temp^set('ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE') do +for event in -temp-set('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 @@ -162,7 +167,7 @@ end tab_info = t do - local data = -temp^list('search_tab', 'Search', 'post_tab', 'Post', 'auctions_tab', 'Auctions', 'bids_tab', 'Bids') + local data = -temp-list('search_tab', 'Search', 'post_tab', 'Post', 'auctions_tab', 'Auctions', 'bids_tab', 'Bids') for i=1,getn(data),2 do log(data[i], data[i + 1]) local tab = -object('name', data[i + 1]) diff --git a/module.lua b/module.lua index ab62c18..c05c9e8 100644 --- a/module.lua +++ b/module.lua @@ -2,7 +2,7 @@ local type, setmetatable, setfenv, unpack, mask, _g = type, setmetatable, setfen local PRIVATE, PUBLIC, MUTABLE, PROPERTY, ACCESSOR, MUTATOR = 0, 1, 2, 4, 8, 16 local error, import_error, modifier_error, property_error, immutable_error, collision_error, set_property, env_mt, interface_mt, declarator_mt, importer_mt local _state, _modules = {}, {} -function error(message, ...) return _g.error(format(message, unpack(arg))..'\n'..debugstack(1, 15, 5), 0) end +function error(message, ...) return _g.error(format(message or '', unpack(arg))..'\n'..debugstack(), 0) end import_error, modifier_error, property_error = function() error 'Invalid modifiers.' end, function() error 'Invalid modifiers.' end, function() error 'Accessor/Mutator must be function.' end immutable_error, collision_error = function(key) error('Field "%s" is immutable.', key) end, function(key) error('Field "%s" already exists.', key) end importer_mt = {__metatable=false} @@ -105,10 +105,9 @@ function module(name) mutators = {accessor=function(f) set_property(state.metadata, accessors, ACCESSOR, state.property, f) end, mutator=function(f) set_property(state.metadata, mutators, MUTATOR, state.property, f) end} state = { env=env, interface=interface, modifiers=PRIVATE, - metadata = {_=MUTABLE, _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}, - data = {_g=_g, _m=env, _i=interface, import=importer}, accessors=accessors, mutators=mutators, + metadata = {_=MUTABLE, _g=PRIVATE, _m=PRIVATE, _i=PRIVATE, error=PRIVATE, import=PRIVATE, private=PROPERTY+ACCESSOR, public=PROPERTY+ACCESSOR, mutable=PROPERTY+ACCESSOR, accessor=PROPERTY+ACCESSOR+MUTATOR, mutator=PROPERTY+ACCESSOR+MUTATOR}, + data = {_g=_g, _m=env, _i=interface, error=error, import=importer}, accessors=accessors, mutators=mutators, } - if not name then error('kek', 2) end _modules[name], _state[env], _state[interface], _state[declarator], _state[importer] = state, state, state, state, state importer [''] 'core' end diff --git a/tabs/search/filter.lua b/tabs/search/filter.lua index 2b4de23..29daba0 100644 --- a/tabs/search/filter.lua +++ b/tabs/search/filter.lua @@ -72,14 +72,14 @@ function update_form() end if blizzard_query.exact then - for key in -temp^set('class', 'subclass', 'slot', 'quality') do + for key in -temp-set('class', 'subclass', 'slot', 'quality') do _m[key..'_dropdown'].button:Disable() end else class_dropdown.button:Enable() quality_dropdown.button:Enable() end - for key in -temp^set('min_level', 'max_level') do + for key in -temp-set('min_level', 'max_level') do if blizzard_query.exact then _m[key..'_input']:Disable() else @@ -134,7 +134,7 @@ function get_filter_builder_query() add(strlower(_g['ITEM_QUALITY'..quality..'_DESC'])) end - local post_filter_string = filter_util.query_string(-temp^object('blizzard', tt, 'post', post_filter)) + local post_filter_string = filter_util.query_string(-temp-object('blizzard', tt, 'post', post_filter)) add(post_filter_string ~= '' and post_filter_string) return query_string or '' @@ -313,7 +313,7 @@ function set_filter_display_offset(x_offset, y_offset) end function initialize_filter_dropdown() - for _, filter in -temp^list('and', 'or', 'not', 'min-unit-bid', 'min-unit-buy', 'max-unit-bid', 'max-unit-buy', 'bid-profit', 'buy-profit', 'bid-vend-profit', 'buy-vend-profit', 'bid-dis-profit', 'buy-dis-profit', 'bid-pct', 'buy-pct', 'item', 'tooltip', 'min-lvl', 'max-lvl', 'rarity')('left', 'utilizable', 'discard') do + for _, filter in -temp-list('and', 'or', 'not', 'min-unit-bid', 'min-unit-buy', 'max-unit-bid', 'max-unit-buy', 'bid-profit', 'buy-profit', 'bid-vend-profit', 'buy-vend-profit', 'bid-dis-profit', 'buy-dis-profit', 'bid-pct', 'buy-pct', 'item', 'tooltip', 'min-lvl', 'max-lvl', 'rarity')('left', 'utilizable', 'discard') do UIDropDownMenu_AddButton(-object( 'text', filter, 'value', filter, diff --git a/util/filter.lua b/util/filter.lua index 41c642a..bd5238b 100644 --- a/util/filter.lua +++ b/util/filter.lua @@ -229,7 +229,7 @@ do end for number in present(tonumber(select(3, strfind(str, '^(%d+)$')))) do if number >= 1 and number <= 60 then - for filter in -temp^set('min_level', 'max_level') do + for filter in -temp-set('min_level', 'max_level') do if not self[filter] then self[filter] = {str, number} return true @@ -517,7 +517,7 @@ function blizzard_query(components) query.slot = slot_index query.quality = item_info.quality else - for key in -temp^set('min_level', 'max_level', 'class', 'subclass', 'slot', 'usable', 'quality') do + for key in -temp-set('min_level', 'max_level', 'class', 'subclass', 'slot', 'usable', 'quality') do query[key] = index(filters[key], 2) end end diff --git a/util/info.lua b/util/info.lua index 48dd614..8c4a1dc 100644 --- a/util/info.lua +++ b/util/info.lua @@ -190,7 +190,7 @@ function public.set_shopping_tooltip(slot) end if tooltips[1] then - tinsert(tooltips[1], 1, -temp^object('left_text', 'Currently Equipped', 'left_color', -temp^list(.5, .5, .5))) + tinsert(tooltips[1], 1, -temp-object('left_text', 'Currently Equipped', 'left_color', -temp-list(.5, .5, .5))) ShoppingTooltip1:SetOwner(GameTooltip, 'ANCHOR_BOTTOMRIGHT') load_tooltip(ShoppingTooltip1, tooltips[1]) ShoppingTooltip1:Show() @@ -198,7 +198,7 @@ function public.set_shopping_tooltip(slot) end if tooltips[2] then - tinsert(tooltips[2], 1, -temp^object('left_text', 'Currently Equipped', 'left_color', -temp^list(.5, .5, .5))) + tinsert(tooltips[2], 1, -temp-object('left_text', 'Currently Equipped', 'left_color', -temp-list(.5, .5, .5))) ShoppingTooltip2:SetOwner(ShoppingTooltip1, 'ANCHOR_BOTTOMRIGHT') load_tooltip(ShoppingTooltip2, tooltips[2]) ShoppingTooltip2:Show()