big refactoring
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
setglobal('aux', aux_module 'core')
|
setglobal('aux', aux_module 'core')
|
||||||
import 'util'
|
|
||||||
|
|
||||||
public.version = '5.0.0'
|
public.version = '5.0.0'
|
||||||
|
|
||||||
|
local temp
|
||||||
do
|
do
|
||||||
local setn = g.table.setn
|
local setn, tinsert, tremove = g.table.setn, g.tinsert, g.tremove
|
||||||
local table_pool, locked = {}
|
local table_pool, locked = {}, {}
|
||||||
local function wipe(t) -- like with a cloth or something
|
local function wipe(t) -- like with a cloth or something
|
||||||
for k in t do t[k] = nil end
|
for k in t do t[k] = nil end
|
||||||
setn(t, 0)
|
setn(t, 0)
|
||||||
@@ -14,12 +14,14 @@ do
|
|||||||
local function release(t)
|
local function release(t)
|
||||||
locked[t] = nil
|
locked[t] = nil
|
||||||
tinsert(table_pool, t)
|
tinsert(table_pool, t)
|
||||||
|
aux.log(getn(table_pool))
|
||||||
end
|
end
|
||||||
function public.temp()
|
function temp()
|
||||||
local t = tremove(table_pool)
|
local t = tremove(table_pool)
|
||||||
t = t and wipe(t) or {}
|
t = t and wipe(t) or {}
|
||||||
locked[t] = true
|
locked[t] = true
|
||||||
end
|
end
|
||||||
|
public.temp = temp
|
||||||
function public.static()
|
function public.static()
|
||||||
local t = tremove(table_pool)
|
local t = tremove(table_pool)
|
||||||
t = t and wipe(t) or {}
|
t = t and wipe(t) or {}
|
||||||
@@ -28,23 +30,22 @@ do
|
|||||||
function public.array(...) locked[arg] = true end
|
function public.array(...) locked[arg] = true end
|
||||||
function public.set(...)
|
function public.set(...)
|
||||||
local set = temp()
|
local set = temp()
|
||||||
for i=1,arg.n do self[arg[i]] = true end
|
for i=1,arg.n do set[arg[i]] = true end
|
||||||
|
release(arg)
|
||||||
return set
|
return set
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local temp = temp
|
|
||||||
|
|
||||||
do
|
do
|
||||||
local aux_module, getfenv, setfenv, gfind, tinsert = g.aux_module, g.getfenv, g.setfenv, g.string.gfind, g.tinsert
|
local aux_module, getfenv, setfenv, gfind = g.aux_module, g.getfenv, g.setfenv, g.string.gfind
|
||||||
local root = (function() aux_module 'modules' return getfenv() end)()
|
aux_module 'modules'
|
||||||
function public.module(path)
|
function public.module(path)
|
||||||
local parts = gfind(path, '[%a_][%w_]*')
|
local parts, name, env
|
||||||
local name = parts() or ''
|
parts, name = gfind(path, '[%a_][%w_]*'), 'modules'
|
||||||
local env = root
|
|
||||||
for part in parts do
|
for part in parts do
|
||||||
env.public[part], env = (function() return aux_module(name), getfenv() end)()
|
env.public[part], env = (function() return aux_module(name), getfenv() end)()
|
||||||
env.import('modules', 'core', 'util')
|
env.import('modules', 'core', 'util')
|
||||||
name = name..'.'..part
|
name = name..'/'..part
|
||||||
end
|
end
|
||||||
setfenv(2, env)
|
setfenv(2, env)
|
||||||
end
|
end
|
||||||
@@ -54,7 +55,9 @@ local event_frame = CreateFrame 'Frame'
|
|||||||
for _, event in {'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)
|
event_frame:RegisterEvent(event)
|
||||||
end
|
end
|
||||||
ADDON_LOADED = {}
|
|
||||||
|
LOADED, LOADED2, ADDON_LOADED = {}, {}, {}
|
||||||
|
function public.accessor.LOAD(f) tinsert(LOAD, f) end
|
||||||
event_frame:SetScript('OnEvent', function()
|
event_frame:SetScript('OnEvent', function()
|
||||||
if event == 'ADDON_LOADED' then
|
if event == 'ADDON_LOADED' then
|
||||||
if ADDON_LOADED[arg1] then
|
if ADDON_LOADED[arg1] then
|
||||||
@@ -63,11 +66,11 @@ event_frame:SetScript('OnEvent', function()
|
|||||||
else
|
else
|
||||||
m[event]()
|
m[event]()
|
||||||
if event == 'VARIABLES_LOADED' then
|
if event == 'VARIABLES_LOADED' then
|
||||||
for _, env in module_envs do
|
-- for _, env in module_envs do
|
||||||
if env.LOAD then
|
-- if env.LOAD then
|
||||||
env.LOAD()
|
-- env.LOAD()
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
log('v'..version..' loaded.')
|
log('v'..version..' loaded.')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+88
-79
@@ -1,85 +1,94 @@
|
|||||||
local tinsert, setfenv, rawget, setmetatable, mask, add, g = tinsert, setfenv, rawget, setmetatable, bit.band, bit.bor, getfenv(0)
|
local rawget, setmetatable, mask, add, g = rawget, setmetatable, bit.band, bit.bor, getfenv(0)
|
||||||
local DECLARED, ACCESSOR, MUTABLE, PUBLIC = 1, 2, 4, 8
|
local DECLARED, ACCESSOR, MUTABLE, PUBLIC = 1, 2, 4, 8
|
||||||
local ACCESSOR_KEY, MUTABLE_KEY, PUBLIC_KEY = 'accessor', 'mutable', 'public'
|
local IMPORTER_KEY, ACCESSOR_KEY, MUTABLE_KEY, PUBLIC_KEY = 'import', 'accessor', 'mutable', 'public'
|
||||||
local PROPERTY = {[ACCESSOR_KEY]=ACCESSOR, [MUTABLE_KEY]=MUTABLE, [PUBLIC_KEY]=PUBLIC}
|
local PROPERTY = {[ACCESSOR_KEY]=ACCESSOR, [MUTABLE_KEY]=MUTABLE, [PUBLIC_KEY]=PUBLIC}
|
||||||
local _data, _metadata, _modifier_properties, _imports, _envs, _interfaces = {}, {}, {}, {}, {}, {}
|
local _modules, _data, _metadata, _modifiers, _modifier_properties, _imports = {}, {}, {}, {}, {}, {}
|
||||||
local function error(message, ...) g.error(format(message, unpack(arg))..'\n'..debugstack(3, 5, 0), 3) end
|
local metadata_mt, modifier_mt, env_mt, interface_mt, importer_mt
|
||||||
local metadata_mt = {__index=function() return 0 end}
|
local modifier_accessor, accessor_modifier_accessor, mutable_modifier_accessor, public_modifier_accessor
|
||||||
local env_mt = {
|
local error, locked
|
||||||
__metatable = false,
|
function error(message, ...) g.error(format(message, unpack(arg))..'\n'..debugstack(3, 5, 0), 3) end
|
||||||
__index = function(self, key)
|
metadata_mt = {__index=function() return 0 end }
|
||||||
local value, properties = _data[self][key], _metadata[self][key]
|
function importer_mt.__call(self, ...)
|
||||||
if mask(DECLARED+ACCESSOR, properties) == DECLARED then
|
local imports = _imports[self]
|
||||||
return value
|
for i = 1, arg.n do imports[arg[i]] = true end
|
||||||
elseif mask(ACCESSOR, properties) == ACCESSOR then
|
end
|
||||||
return value(key)
|
function modifier_accessor(property)
|
||||||
else
|
return function(modifier) return function() _modifier_properties[modifier] = DECLARED+property return modifier end end
|
||||||
for _, name in _imports[self] do
|
end
|
||||||
local interface = _interfaces[name]
|
accessor_modifier_accessor, mutable_modifier_accessor, public_modifier_accessor = modifier_accessor(ACCESSOR), modifier_accessor(MUTABLE), modifier_accessor(PUBLIC)
|
||||||
if interface and mask(PUBLIC, _metadata[interface][key]) ~= 0 then
|
modifier_mt = {__metatable=false}
|
||||||
return interface[key]
|
function modifier_mt.__index(self, key)
|
||||||
|
local property = PROPERTY[key]
|
||||||
|
if not property then error('Unknown modifier "%s".', key) end
|
||||||
|
_modifier_properties[self] = add(property, _modifier_properties[self])
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
function modifier_mt.__newindex(self, key, value)
|
||||||
|
if rawget(_metadata[self], key) then error('Field "%s" already exists.', key) end
|
||||||
|
_metadata[self][key], _data[self][key] = _modifier_properties[self], value
|
||||||
|
end
|
||||||
|
env_mt = {__metatable=false}
|
||||||
|
function env_mt.__index(self, key)
|
||||||
|
local value, properties = _data[self][key], _metadata[self][key]
|
||||||
|
if mask(DECLARED + ACCESSOR, properties) == DECLARED then
|
||||||
|
return value
|
||||||
|
elseif mask(ACCESSOR, properties) == ACCESSOR then
|
||||||
|
return value(key)
|
||||||
|
else
|
||||||
|
return g[key] or error('No field "%s".', key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function env_mt.__newindex(self, key, value)
|
||||||
|
if not rawget(_metadata[self], key) then
|
||||||
|
_metadata[self][key] = DECLARED
|
||||||
|
elseif mask(MUTABLE, _metadata[self][key]) == 0 then
|
||||||
|
error('Field "%s" is immutable.', key)
|
||||||
|
end
|
||||||
|
_data[self][key] = value
|
||||||
|
end
|
||||||
|
interface_mt = {__metatable=false}
|
||||||
|
function interface_mt.__index(self, key)
|
||||||
|
local value, properties = _data[self][key], _metadata[self][key]
|
||||||
|
if mask(ACCESSOR + PUBLIC, properties) == PUBLIC then
|
||||||
|
return value
|
||||||
|
elseif mask(PUBLIC, properties) ~= 0 or error('No field "%s".', key) then
|
||||||
|
return value(key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function interface_mt.__newindex(self, key, value) self[key](value) end
|
||||||
|
importer_mt = {__metatable=false}
|
||||||
|
function g.aux_module(name)
|
||||||
|
if not _modules[name] then
|
||||||
|
local metadata, data, imports, importer, modifier, env, interface
|
||||||
|
imports, importer, modifier, env, interface = {}, setmetatable({}, importer_mt), setmetatable({}, modifier_mt), setmetatable({}, env_mt), setmetatable({}, interface_mt)
|
||||||
|
metadata = setmetatable({g=DECLARED, m=DECLARED, [IMPORTER_KEY]=DECLARED, [ACCESSOR_KEY]=ACCESSOR, [MUTABLE_KEY]=ACCESSOR, [PUBLIC_KEY]=ACCESSOR}, metadata_mt)
|
||||||
|
data = {g=g, m=env, [IMPORTER_KEY]=importer, [ACCESSOR_KEY]=accessor_modifier_accessor(modifier), [MUTABLE_KEY]=mutable_modifier_accessor(modifier), [PUBLIC_KEY]=public_modifier_accessor(modifier)}
|
||||||
|
_metadata[name], _metadata[modifier], _metadata[env], _metadata[interface] = metadata, metadata, metadata, metadata
|
||||||
|
_data[name], _data[modifier], _data[env], _data[interface] = data, data, data, data
|
||||||
|
_imports[name], _imports[importer] = imports, imports
|
||||||
|
_modifiers[name] = modifier
|
||||||
|
_modules[name] = {env, interface}
|
||||||
|
end
|
||||||
|
return _modules[name]
|
||||||
|
end
|
||||||
|
local frame = CreateFrame 'Frame'
|
||||||
|
frame:RegisterEvent 'PLAYER_LOGIN'
|
||||||
|
frame:SetScript('OnEvent', function()
|
||||||
|
locked = true
|
||||||
|
local count = 0
|
||||||
|
local t0 = GetTime()
|
||||||
|
for name in _modules do
|
||||||
|
local modifier = _modifiers[name]
|
||||||
|
for import_name in _imports[name] do
|
||||||
|
if not _modules[import_name] then error('Invalid import %s in %s.', import_name, name) end
|
||||||
|
local data = _data[import_name]
|
||||||
|
for key, properties in _metadata[import_name] do
|
||||||
|
if mask(PUBLIC, properties) ~= 0 then
|
||||||
|
_modifier_properties[modifier] = properties
|
||||||
|
modifier[key] = data[key]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return g[key] or error('No field "%s".', key)
|
|
||||||
end
|
end
|
||||||
end,
|
|
||||||
__newindex = function(self, key, value)
|
|
||||||
if not rawget(_metadata[self], key) then
|
|
||||||
_metadata[self][key] = DECLARED
|
|
||||||
elseif mask(MUTABLE, _metadata[self][key]) == 0 then
|
|
||||||
error('Field "%s" is immutable.', key)
|
|
||||||
end
|
|
||||||
_data[self][key] = value
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
local interface_mt = {
|
|
||||||
__metatable = false,
|
|
||||||
__index = function(self, key)
|
|
||||||
local value, properties = _data[self][key], _metadata[self][key]
|
|
||||||
if mask(ACCESSOR+PUBLIC, properties) == PUBLIC then
|
|
||||||
return value
|
|
||||||
elseif mask(PUBLIC, properties) ~= 0 then
|
|
||||||
return value(key)
|
|
||||||
else
|
|
||||||
error('No field "%s".', key)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
__newindex = function(self, key, value) self[key](value) end,
|
|
||||||
}
|
|
||||||
local modifier_mt = {
|
|
||||||
__metatable = false,
|
|
||||||
__index = function(self, key)
|
|
||||||
local property = PROPERTY[key]
|
|
||||||
if not property then error('Unknown modifier "%s".', key) end
|
|
||||||
_modifier_properties[self] = add(property, _modifier_properties[self])
|
|
||||||
return self
|
|
||||||
end,
|
|
||||||
__newindex = function(self, key, value)
|
|
||||||
if rawget(_metadata[self], key) then error('Field "%s" already exists.', key) end
|
|
||||||
_metadata[self][key] = _modifier_properties[self]
|
|
||||||
_data[self][key] = value
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
local importer_mt = {
|
|
||||||
__call = function(self, ...)
|
|
||||||
for i=1,arg.n do
|
|
||||||
tinsert(_imports[self], arg[i])
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
function g.aux_module(name)
|
|
||||||
if not _envs[name] then
|
|
||||||
local data, metadata, imports, importer, modifier, env, interface, modifier_accessor
|
|
||||||
modifier, importer, env, interface = setmetatable({}, modifier_mt), setmetatable({}, importer_mt), setmetatable({}, env_mt), setmetatable({}, interface_mt)
|
|
||||||
function modifier_accessor(key) _modifier_properties[modifier] = DECLARED+PROPERTY[key] return modifier end
|
|
||||||
data = {g=g, m=env, import=importer, [ACCESSOR_KEY]=modifier_accessor, [MUTABLE_KEY]=modifier_accessor, [PUBLIC_KEY]=modifier_accessor}
|
|
||||||
metadata = setmetatable({g=DECLARED, m=DECLARED, import=DECLARED, [ACCESSOR_KEY]=ACCESSOR, [MUTABLE_KEY]=ACCESSOR, [PUBLIC_KEY]=ACCESSOR}, metadata_mt)
|
|
||||||
imports = {}
|
|
||||||
_envs[name], _interfaces[name] = env, interface
|
|
||||||
_data[modifier], _data[env], _data[interface] = data, data, data
|
|
||||||
_metadata[modifier], _metadata[env], _metadata[interface] = metadata, metadata, metadata
|
|
||||||
_imports[importer], _imports[env] = imports, imports
|
|
||||||
end
|
end
|
||||||
setfenv(2, _envs[name])
|
aux.log('imported: '..count..' in '..(GetTime()-t0))
|
||||||
return _interfaces[name]
|
end)
|
||||||
end
|
|
||||||
+25
-25
@@ -6,31 +6,6 @@ function valid_level(str)
|
|||||||
end
|
end
|
||||||
|
|
||||||
blizzard_query = setmetatable({}, {
|
blizzard_query = setmetatable({}, {
|
||||||
__newindex = function(_, key, value)
|
|
||||||
if key == 'name' then
|
|
||||||
name_input:SetText(value)
|
|
||||||
elseif key == 'exact' then
|
|
||||||
exact_checkbox:SetChecked(value)
|
|
||||||
elseif key == 'min_level' then
|
|
||||||
min_level_input:SetText(value)
|
|
||||||
elseif key == 'max_level' then
|
|
||||||
max_level_input:SetText(value)
|
|
||||||
elseif key == 'usable' then
|
|
||||||
usable_checkbox:SetChecked(value)
|
|
||||||
elseif key == 'class' then
|
|
||||||
UIDropDownMenu_Initialize(class_dropdown, initialize_class_dropdown)
|
|
||||||
UIDropDownMenu_SetSelectedValue(class_dropdown, value)
|
|
||||||
elseif key == 'subclass' then
|
|
||||||
UIDropDownMenu_Initialize(subclass_dropdown, initialize_subclass_dropdown)
|
|
||||||
UIDropDownMenu_SetSelectedValue(subclass_dropdown, value)
|
|
||||||
elseif key == 'slot' then
|
|
||||||
UIDropDownMenu_Initialize(slot_dropdown, initialize_slot_dropdown)
|
|
||||||
UIDropDownMenu_SetSelectedValue(slot_dropdown, value)
|
|
||||||
elseif key == 'quality' then
|
|
||||||
UIDropDownMenu_Initialize(quality_dropdown, initialize_quality_dropdown)
|
|
||||||
UIDropDownMenu_SetSelectedValue(quality_dropdown, value)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
__index = function(_, key)
|
__index = function(_, key)
|
||||||
if key == 'name' then
|
if key == 'name' then
|
||||||
return name_input:GetText()
|
return name_input:GetText()
|
||||||
@@ -56,6 +31,31 @@ blizzard_query = setmetatable({}, {
|
|||||||
return (quality_code or -1) >= 0 and quality_code or nil
|
return (quality_code or -1) >= 0 and quality_code or nil
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
__newindex = function(_, key, value)
|
||||||
|
if key == 'name' then
|
||||||
|
name_input:SetText(value)
|
||||||
|
elseif key == 'exact' then
|
||||||
|
exact_checkbox:SetChecked(value)
|
||||||
|
elseif key == 'min_level' then
|
||||||
|
min_level_input:SetText(value)
|
||||||
|
elseif key == 'max_level' then
|
||||||
|
max_level_input:SetText(value)
|
||||||
|
elseif key == 'usable' then
|
||||||
|
usable_checkbox:SetChecked(value)
|
||||||
|
elseif key == 'class' then
|
||||||
|
UIDropDownMenu_Initialize(class_dropdown, initialize_class_dropdown)
|
||||||
|
UIDropDownMenu_SetSelectedValue(class_dropdown, value)
|
||||||
|
elseif key == 'subclass' then
|
||||||
|
UIDropDownMenu_Initialize(subclass_dropdown, initialize_subclass_dropdown)
|
||||||
|
UIDropDownMenu_SetSelectedValue(subclass_dropdown, value)
|
||||||
|
elseif key == 'slot' then
|
||||||
|
UIDropDownMenu_Initialize(slot_dropdown, initialize_slot_dropdown)
|
||||||
|
UIDropDownMenu_SetSelectedValue(slot_dropdown, value)
|
||||||
|
elseif key == 'quality' then
|
||||||
|
UIDropDownMenu_Initialize(quality_dropdown, initialize_quality_dropdown)
|
||||||
|
UIDropDownMenu_SetSelectedValue(quality_dropdown, value)
|
||||||
|
end
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
function update_form()
|
function update_form()
|
||||||
|
|||||||
Reference in New Issue
Block a user