refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-07-16 12:09:15 +02:00
parent 55d7b78962
commit 3fcb107ff5
5 changed files with 89 additions and 101 deletions
+2 -1
View File
@@ -3,8 +3,9 @@
## SavedVariablesPerCharacter: aux_ignore_owner, aux_recent_searches, aux_favorite_searches, aux_price_per_unit, aux_tooltip_value, aux_tooltip_daily, aux_tooltip_vendor_buy, aux_tooltip_vendor_sell, aux_tooltip_disenchant_value, aux_tooltip_disenchant_distribution, aux_tooltip_disenchant_source
## SavedVariables: aux_datasets, aux_items, aux_item_ids, aux_auctionable_items, aux_merchant_buy, aux_merchant_sell, aux_characters
module.lua
core.xml
control.xml
control.lua
gui.lua
+8 -2
View File
@@ -1,9 +1,15 @@
local m, public, private = Aux.module'control'
private.event_frame = CreateFrame('Frame')
private.event_listeners = {}
private.threads = {}
public.thread_id = nil
function public.LOAD()
m.event_frame:SetScript('OnUpdate', m.on_update)
m.event_frame:SetScript('OnEvent', m.on_event)
end
function public.on_event()
for listener, _ in m.event_listeners do
if event == listener.event and not listener.deleted then
@@ -47,14 +53,14 @@ function public.event_listener(event, action)
function self:start()
Aux.util.set_add(m.event_listeners, listener)
AuxControlFrame:RegisterEvent(event)
m.event_frame:RegisterEvent(event)
return self
end
function self:stop()
listener.deleted = true
if not Aux.util.any(Aux.util.set_to_array(m.event_listeners), function(l) return l.event == event end) then
AuxControlFrame:UnregisterEvent(event)
m.event_frame:UnregisterEvent(event)
end
return self
end
-15
View File
@@ -1,15 +0,0 @@
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
<Script file="control.lua"/>
<Frame name="AuxControlFrame">
<Scripts>
<OnEvent>
Aux.control.on_event()
</OnEvent>
<OnUpdate>
Aux.control.on_update()
</OnUpdate>
</Scripts>
</Frame>
</Ui>
-83
View File
@@ -1,86 +1,3 @@
local wrap, unwrap = (function()
local null = {}
return function(value)
if value == nil then
return null
else
return value
end
end,
function(value)
if value == null then
return nil
else
return value
end
end
end)()
local function Aux_module(name)
local data, is_public, public_interface, private_interface, public, private = {}, {}, {}, {}, {}, {}
setmetatable(public_interface, {
__newindex = function(_, key)
error('Illegal write of attribute "'..key..'" on public interface of "'..name..'"!')
end,
__index = function(_, key)
if data[key] == nil then
error('Access of undeclared attribute "'..key..'" on public interface of "'..name..'"!')
end
if is_public[key] then
return unwrap(data[key])
end
end,
__call = function(_, key)
return is_public[key]
end
})
setmetatable(private_interface, {
__newindex = function(_, key, value)
if data[key] == nil then
error('Assignment of undeclared attribute "'..key..'" on private interface of "'..name..'"!')
end
data[key] = wrap(value)
end,
__index = function(_, key)
if data[key] == nil then
error('Access of undeclared attribute "'..key..'" on private interface of "'..name..'"!')
end
return unwrap(data[key])
end,
__call = function(_, key)
return data[key] ~= nil
end
})
setmetatable(public, {
__newindex = function(_, key, value)
if data[key] ~= nil then
error('Multiple declarations of "'..key..'" in "'..name..'"!')
end
data[key] = wrap(value)
is_public[key] = true
end,
__index = function(_, key)
error('Illegal read of attribute "'..key..'" on public keyword in "'..name..'"!')
end,
})
setmetatable(private, {
__newindex = function(_, key, value)
if data[key] ~= nil then
error('Multiple declarations of "'..key..'" in "'..name..'"!')
end
data[key] = wrap(value)
is_public[key] = nil
end,
__index = function(_, key)
error('Illegal read of attribute "'..key..'" on private keyword in "'..name..'"!')
end,
})
return { public_interface, private_interface, public, private }
end
-----------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
local addon = Aux_module('Aux')
Aux = tremove(addon, 1)
local m, public, private = unpack(addon)
+79
View File
@@ -0,0 +1,79 @@
local wrap, unwrap = (function()
local null = {}
return function(value)
if value == nil then
return null
else
return value
end
end,
function(value)
if value == null then
return nil
else
return value
end
end
end)()
function Aux_module(name)
local data, is_public, public_interface, private_interface, public, private = {}, {}, {}, {}, {}, {}
setmetatable(public_interface, {
__newindex = function(_, key)
error('Illegal write of attribute "'..key..'" on public interface of "'..name..'"!')
end,
__index = function(_, key)
if data[key] == nil then
error('Access of undeclared attribute "'..key..'" on public interface of "'..name..'"!')
end
if is_public[key] then
return unwrap(data[key])
end
end,
__call = function(_, key)
return is_public[key]
end
})
setmetatable(private_interface, {
__newindex = function(_, key, value)
if data[key] == nil then
error('Assignment of undeclared attribute "'..key..'" on private interface of "'..name..'"!')
end
data[key] = wrap(value)
end,
__index = function(_, key)
if data[key] == nil then
error('Access of undeclared attribute "'..key..'" on private interface of "'..name..'"!')
end
return unwrap(data[key])
end,
__call = function(_, key)
return data[key] ~= nil
end
})
setmetatable(public, {
__newindex = function(_, key, value)
if data[key] ~= nil then
error('Multiple declarations of "'..key..'" in "'..name..'"!')
end
data[key] = wrap(value)
is_public[key] = true
end,
__index = function(_, key)
error('Illegal read of attribute "'..key..'" on public keyword in "'..name..'"!')
end,
})
setmetatable(private, {
__newindex = function(_, key, value)
if data[key] ~= nil then
error('Multiple declarations of "'..key..'" in "'..name..'"!')
end
data[key] = wrap(value)
is_public[key] = nil
end,
__index = function(_, key)
error('Illegal read of attribute "'..key..'" on private keyword in "'..name..'"!')
end,
})
return { public_interface, private_interface, public, private }
end