refactoring
This commit is contained in:
+3
-6
@@ -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
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+15
-12
@@ -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
|
||||
+2
-2
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
+3
-4
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user