big refactoring
This commit is contained in:
@@ -7,7 +7,7 @@ end
|
||||
|
||||
public.version = '5.0.0'
|
||||
|
||||
local temp, recycle
|
||||
local t, temp, recycle
|
||||
do
|
||||
local table_pool, locked = {}, {}
|
||||
local function wipe(t) -- like with a cloth or something
|
||||
@@ -17,19 +17,23 @@ do
|
||||
end
|
||||
function recycle(t)
|
||||
locked[t] = nil
|
||||
tinsert(table_pool, t)
|
||||
tinsert(table_pool, wipe(t))
|
||||
log(getn(table_pool))
|
||||
end
|
||||
public.recycle = recycle
|
||||
temp = setmetatable({}, {
|
||||
__call = function()
|
||||
local t = tremove(table_pool)
|
||||
t = t and wipe(t) or {}
|
||||
local t = tremove(table_pool) or {}
|
||||
locked[t] = true
|
||||
return t
|
||||
end,
|
||||
__sub = function(_, t) locked[t] = true return t end,
|
||||
})
|
||||
public.temp = temp
|
||||
function t()
|
||||
return tremove(table_pool) or {}
|
||||
end
|
||||
public.accessor.t = t
|
||||
end
|
||||
|
||||
do
|
||||
@@ -47,7 +51,7 @@ do
|
||||
end
|
||||
|
||||
local event_frame = CreateFrame 'Frame'
|
||||
for event in temp-set{'VARIABLES_LOADED', 'ADDON_LOADED', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE'} do
|
||||
for _, event in {'VARIABLES_LOADED', 'ADDON_LOADED', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE'} do
|
||||
event_frame:RegisterEvent(event)
|
||||
end
|
||||
|
||||
|
||||
+5
-6
@@ -1,6 +1,7 @@
|
||||
local setmetatable, unpack, mask, add, g = setmetatable, unpack, bit.band, bit.bor, getfenv(0)
|
||||
local PRIVATE, PUBLIC, MUTABLE, ACCESSOR, MUTATOR = 1, 2, 4, 8, 16
|
||||
local MODIFIER = {private=PRIVATE, public=PUBLIC, mutable=MUTABLE, accessor=ACCESSOR, mutator=MUTATOR}
|
||||
local MASK = {private=MUTABLE+ACCESSOR+MUTATOR, public=MUTABLE+ACCESSOR+MUTATOR, mutable=PRIVATE+PUBLIC, accessor=PRIVATE+PUBLIC+MUTATOR, mutator=PRIVATE+PUBLIC+ACCESSOR}
|
||||
local _10, _01, tf, ft = {[true]=1, [false]=0}, {[true]=0, [false]=1}, {true, false}, {false, true}
|
||||
local importer_mt, declarator_mt, env_mt, interface_mt, lock_mt
|
||||
local define_property, declarator_accessor, private_accessor, public_accessor, mutable_accessor, accessor_accessor, mutator_accessor, index, error
|
||||
@@ -17,21 +18,19 @@ end
|
||||
private_accessor, public_accessor, mutable_accessor, accessor_accessor, mutator_accessor = declarator_accessor(0), declarator_accessor(PUBLIC), declarator_accessor(MUTABLE), declarator_accessor(ACCESSOR), declarator_accessor(MUTATOR)
|
||||
function define_property(self, key, t)
|
||||
local accessor, mutator = t.get, t.set
|
||||
_declarator_state[self] = add(_01[not accessor]*ACCESSOR, _01[not mutator]*MUTATOR, _declarator_state[self])
|
||||
_declarator_state[self] = _01[not accessor]*ACCESSOR + _01[not mutator]*MUTATOR + mask(PRIVATE+PUBLIC, _declarator_state[self])
|
||||
_accessors[self][key], _mutators[self][key] = accessor, mutator
|
||||
end
|
||||
declarator_mt = {__metatable=false}
|
||||
function declarator_mt.__index(self, key)
|
||||
local modifier = MODIFIER[key]
|
||||
if not modifier then return function(t) define_property(self, key, t) end end
|
||||
_declarator_state[self] = add(modifier, _declarator_state[self])
|
||||
_declarator_state[self] = modifier + mask(MASK[key], _declarator_state[self])
|
||||
return self
|
||||
end
|
||||
function declarator_mt.__newindex(self, key, value)
|
||||
if _metadata[self][key] then error('Field "%s" already exists.', key) end
|
||||
local modifiers = _declarator_state[self]
|
||||
if mask(MUTABLE, modifiers) * mask(ACCESSOR+MUTABLE) ~= 0 then error('Invalid modifiers.') end
|
||||
_metadata[self][key], _data[self][key], _accessors[self][key], _mutators[self][key] = modifiers, value, value, value
|
||||
_metadata[self][key], _data[self][key], _accessors[self][key], _mutators[self][key] = _declarator_state[self], value, value, value
|
||||
end
|
||||
function index(access, default)
|
||||
return function(self, key)
|
||||
@@ -39,7 +38,7 @@ function index(access, default)
|
||||
if mask(access+ACCESSOR+MUTATOR, modifiers) == access then
|
||||
return _data[self][key]
|
||||
elseif mask(access+ACCESSOR, modifiers) == access+ACCESSOR then
|
||||
return _accessors[self]()
|
||||
return _accessors[self][key]()
|
||||
else
|
||||
return default[key] or error('No field "%s".', key)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user