refactoring
This commit is contained in:
+31
-28
@@ -70,23 +70,27 @@ do
|
||||
recycle(self)
|
||||
return raw and setmetatable(f(value), nil) or f(value)
|
||||
end
|
||||
return {__unm=function(self) self.raw = true end, __call=apply, __sub=apply}
|
||||
return {__unm=function(self) self.raw = true; return self end, __call=apply, __sub=apply}
|
||||
end
|
||||
do
|
||||
local mt = operator_mt(function(t) transient[t] = true return t end)
|
||||
public.temp
|
||||
{
|
||||
get = function() return setmetatable(t, mt) end,
|
||||
set = function(t) make_transient(t) end,
|
||||
}
|
||||
end
|
||||
do
|
||||
local mt = operator_mt(function(t) transient[t] = nil return t end)
|
||||
public.perm
|
||||
{
|
||||
get = function() return setmetatable(t, mt) end,
|
||||
set = function(t) make_persistent(t) end,
|
||||
}
|
||||
local function make_transient(t) transient[t] = true; return t end
|
||||
local function make_persistent(t) transient[t] = nil; return t end
|
||||
do
|
||||
local mt = operator_mt(make_transient)
|
||||
public.temp
|
||||
{
|
||||
get = function() return setmetatable(t, mt) end,
|
||||
set = function(t) return make_transient(t) end,
|
||||
}
|
||||
end
|
||||
do
|
||||
local mt = operator_mt(make_persistent)
|
||||
public.perm
|
||||
{
|
||||
get = function() return setmetatable(t, mt) end,
|
||||
set = function(t) return make_persistent(t) end,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local function insert_keys(t,k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15,k16,k17,k18,k19,k20,overflow)
|
||||
@@ -155,9 +159,11 @@ do
|
||||
return {__call=f, __unm=function(self) return setmetatable(self, nil) end}
|
||||
end
|
||||
local set_mt, list_mt, object_mt = collector_mt(insert_keys), collector_mt(insert_values), collector_mt(insert_pairs)
|
||||
function public.set.get() return setmetatable(t, set_mt) end
|
||||
function public.list.get() return setmetatable(t, list_mt) end
|
||||
function public.object.get() return setmetatable(t, object_mt) end
|
||||
public()
|
||||
function set.get() return setmetatable(t, set_mt) end
|
||||
function list.get() return setmetatable(t, list_mt) end
|
||||
function object.get() return setmetatable(t, object_mt) end
|
||||
private()
|
||||
end
|
||||
|
||||
function public.log(...) temp=arg
|
||||
@@ -168,7 +174,6 @@ 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
|
||||
log(event)
|
||||
event_frame:RegisterEvent(event)
|
||||
end
|
||||
|
||||
@@ -195,15 +200,13 @@ end
|
||||
|
||||
tab_info = t
|
||||
do
|
||||
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])
|
||||
local env = (function() module(data[i]) return M end)()
|
||||
function env.OPEN.set(f) tab.OPEN = f end
|
||||
function env.CLOSE.set(f) tab.CLOSE = f end
|
||||
function env.USE_ITEM.set(f) tab.USE_ITEM = f end
|
||||
function env.CLICK_LINK.set(f) tab.CLICK_LINK = f end
|
||||
for k, v in -temp-object('search_tab', 'Search', 'post_tab', 'Post', 'auctions_tab', 'Auctions', 'bids_tab', 'Bids') do
|
||||
local tab = -object('name', v)
|
||||
local env = (function() aux(v) return M end)()
|
||||
function env.private.OPEN.set(f) tab.OPEN = f end
|
||||
function env.private.CLOSE.set(f) tab.CLOSE = f end
|
||||
function env.private.USE_ITEM.set(f) tab.USE_ITEM = f end
|
||||
function env.private.CLICK_LINK.set(f) tab.CLICK_LINK = f end
|
||||
function env.public.ACTIVE.get() return tab == active_tab end
|
||||
tinsert(tab_info, tab)
|
||||
end
|
||||
|
||||
+10
-7
@@ -24,7 +24,7 @@ do
|
||||
return f, getter, setter
|
||||
end
|
||||
local function declare(state, access, name, data)
|
||||
state.access[name] = state.access[name] and collision_error(name) or access or state.default_access
|
||||
state.access[name] = state.access[name] and collision_error(name) or access or state.default_access or declaration_error()
|
||||
for type, value in data do
|
||||
if typeof(value) ~= 'function' and (type == GETTER or declaration_error()) then
|
||||
value = const(value == nil and tostring(value) or value)
|
||||
@@ -51,9 +51,13 @@ do
|
||||
state.declaration_access, state.declaration_name = nil, nil
|
||||
end
|
||||
function declarator_mt:__call(value) local state=_state[self]
|
||||
local success, f, getter, setter = pcall(extract, value)
|
||||
if not (success and state.declaration_name) then declaration_error() end
|
||||
declare(state, state.declaration_access, state.declaration_name, {[FUNCTION]=f, [GETTER]=getter, [SETTER]=setter})
|
||||
if state.declaration_name then
|
||||
local success, f, getter, setter = pcall(extract, value)
|
||||
if not success then declaration_error() end
|
||||
declare(state, state.declaration_access, state.declaration_name, {[FUNCTION]=f, [GETTER]=getter, [SETTER]=setter})
|
||||
elseif state.declaration_access or declaration_error() then
|
||||
state.default_access = state.declaration_access
|
||||
end
|
||||
state.declaration_access, state.declaration_name = nil, nil
|
||||
end
|
||||
end
|
||||
@@ -62,8 +66,7 @@ local env_mt = {__metatable=false}
|
||||
function env_mt:__index(key) local state=_state[self]
|
||||
local getter = state[GETTER][key]
|
||||
if getter then return getter() end
|
||||
local f = state[FUNCTION][key]
|
||||
if f then return f else return _G[key] end
|
||||
return state[FUNCTION][key] or _G[key] or state.declarator[key]
|
||||
end
|
||||
function env_mt:__newindex(key, value) local state=_state[self]
|
||||
if state.access[key] then
|
||||
@@ -90,7 +93,7 @@ function module(...)
|
||||
declarator, env, interface = setmetatable({}, declarator_mt), setmetatable({}, env_mt), setmetatable({}, interface_mt)
|
||||
access = {error=PRIVATE, nop=PRIVATE, _G=PRIVATE, M=PRIVATE, I=PRIVATE, public=PRIVATE, private=PRIVATE}
|
||||
functions = {error=error, nop=nop}
|
||||
getters = {_G=const(_G), M=const(env), I=const(interface), public=function() state.declaration_access = PUBLIC return declarator end, private=function() state.declaration_access = PRIVATE return declarator end}
|
||||
getters = {_G=const(_G), M=const(env), I=const(interface), public=function() state.declaration_access = PUBLIC; return declarator end, private=function() state.declaration_access = PRIVATE; return declarator end}
|
||||
setters = {}
|
||||
for i=1,arg.n do
|
||||
local module = _state[arg[i] or import_error()] or import_error()
|
||||
|
||||
@@ -19,6 +19,15 @@ do
|
||||
}
|
||||
end
|
||||
|
||||
function property.get() end
|
||||
function property.set() end
|
||||
auto_buy_validator = property
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
do
|
||||
local searches = t
|
||||
local search_index = 1
|
||||
|
||||
Reference in New Issue
Block a user