diff --git a/aux-addon.lua b/aux-addon.lua index c57d413..a0d4f5c 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -19,10 +19,11 @@ do __newindex = error, __call = function(self, name) if not modules[name] then - module(aux.core) + module() private.aux = self modules[name] = {env=M, interface=I} end + modules[name].env.import(modules.core.interface) setfenv(2, modules[name].env) end, }) @@ -63,7 +64,7 @@ do else tinsert(overflow_pool, t) end - log(getn(pool), '-', getn(overflow_pool)) +-- log(getn(pool), '-', getn(overflow_pool)) end function public.t.get() @@ -173,8 +174,6 @@ do private() end -(function(...) log( _G.arg) 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 event_frame:RegisterEvent(event) @@ -193,8 +192,6 @@ do elseif event == 'PLAYER_LOGIN' then for _, f in handlers2 do f() end log('v'..version..' loaded.') - - -- TODO test __lt else M[event]() end diff --git a/control.lua b/control.lua index 6ebe826..a7ac89d 100644 --- a/control.lua +++ b/control.lua @@ -27,8 +27,8 @@ function UPDATE() end end - listeners = filter(listeners, function(l) return not l.killed end) -- TODO wipe tables instead - threads = filter(threads, function(th) return not th.killed end) + filter(listeners, function(l) return not l.killed end) + filter(threads, function(th) return not th.killed end) for id, thread in threads do if not thread.killed then diff --git a/core/scan.lua b/core/scan.lua index e19748f..7f8a360 100644 --- a/core/scan.lua +++ b/core/scan.lua @@ -38,7 +38,7 @@ do end function private.state.get() - local _, state = next(filter(scan_states, function(state) return state.id == thread_id end)) + local _, state = next(filter(copy(scan_states), function(state) return state.id == thread_id end)) return state end end diff --git a/libs/module.lua b/libs/module.lua index 08500b9..420b651 100644 --- a/libs/module.lua +++ b/libs/module.lua @@ -5,8 +5,8 @@ local PUBLIC, PRIVATE = 1, 2 local CALL, INDEX, NEWINDEX = 1, 2, 3 local function error(msg, ...) return _G.error(format(msg or '', unpack(arg))..'\n'..debugstack(), 0) end -local function import_error() error 'Import failed.' end -local function declaration_error() error 'Invalid declaration.' end +local function import_error() error('Import error.') end +local function declaration_error() error('Declaration error.') end local function collision_error(key) error('"%s" already exists.', key) end local function nop() end @@ -88,16 +88,7 @@ function interface_mt:__newindex(key, value) self=state[self] if self.access[key] == PUBLIC then (self[NEWINDEX][key] or nop)(value) end end -function module(...) - local declarator, env, interface = setmetatable({}, declarator_mt), setmetatable({}, env_mt), setmetatable({}, interface_mt) - local self; self = { - access = {_=PRIVATE, error=PRIVATE, nop=PRIVATE, _G=PRIVATE, M=PRIVATE, I=PRIVATE, public=PRIVATE, private=PRIVATE}, - [CALL] = {error=error, nop=nop}, - [INDEX] = {_G=const(_G), M=const(env), I=const(interface), public=function() return declarator.public end, private=function() return declarator.private end}, - [NEWINDEX] = {_=nop}, - declarator = declarator, - default_access = PRIVATE, - } +local function import(self, ...) for i = 1, arg.n do local module = state[arg[i] or import_error()] for k, v in module.access do @@ -106,6 +97,18 @@ function module(...) end end end +end + +function module(...) + local declarator, env, interface = setmetatable({}, declarator_mt), setmetatable({}, env_mt), setmetatable({}, interface_mt) + local self; self = { + access = {_=PRIVATE, error=PRIVATE, nop=PRIVATE, _G=PRIVATE, M=PRIVATE, I=PRIVATE, public=PRIVATE, private=PRIVATE}, + [CALL] = {import=function(...) import(self, unpack(arg)) end, error=error, nop=nop}, + [INDEX] = {_G=const(_G), M=const(env), I=const(interface), public=function() return declarator.public end, private=function() return declarator.private end}, + [NEWINDEX] = {_=nop}, + declarator = declarator, + default_access = PRIVATE, + } state[declarator], state[env], state[interface] = self, self, self setfenv(2, env) end \ No newline at end of file diff --git a/tabs/post/core.lua b/tabs/post/core.lua index 25bc23a..ddc993f 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -88,7 +88,7 @@ end function update_inventory_listing() if not ACTIVE then return end - item_listing.populate(inventory_listing, values(filter(inventory_records, function(record) + item_listing.populate(inventory_listing, values(filter(copy(inventory_records), function(record) local settings = read_settings(record.key) return record.aux_quantity > 0 and (not settings.hidden or show_hidden_checkbox:GetChecked()) end))) @@ -168,7 +168,7 @@ function update_auction_listing() end function public.select_item(item_key) - for _, inventory_record in filter(inventory_records, function(record) return record.aux_quantity > 0 end) do + for _, inventory_record in filter(copy(inventory_records), function(record) return record.aux_quantity > 0 end) do if inventory_record.key == item_key then set_item(inventory_record) return diff --git a/util/color.lua b/util/color.lua index 4aaf9c1..c8c8a55 100644 --- a/util/color.lua +++ b/util/color.lua @@ -50,7 +50,6 @@ do end } public.color.get = color_accessor(function(color) - log'kek' local r, g, b, a = unpack(color) return setmetatable({r/255, g/255, b/255, a}, mt) end) diff --git a/util/core.lua b/util/core.lua index 73c67e6..9808745 100644 --- a/util/core.lua +++ b/util/core.lua @@ -190,13 +190,12 @@ function public.all(t, p) end function public.filter(t, p) - local filtered = M.t for k, v in t do - if p(v, k) then - filtered[k] = v + if not p(v, k) then + t[k] = nil end end - return filtered + return t end function public.map(t, f)