From cb3b336625e11c52d57ea1586d5e5b7f9068a88f Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Sat, 10 Sep 2016 13:35:30 +0200 Subject: [PATCH] backup --- aux-addon.lua | 1 - libs/module.lua | 44 +++++++++++++++++++---------------------- tabs/post/core.lua | 12 +++++++---- tabs/search/results.lua | 6 ++++-- util/money.lua | 8 +++----- util/sort.lua | 10 +++++----- 6 files changed, 40 insertions(+), 41 deletions(-) diff --git a/aux-addon.lua b/aux-addon.lua index cee012f..a0b920b 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -13,7 +13,6 @@ do local modules = {} end)() end modules[name].import (modules.core._I) - modules[name].private() setfenv(2, modules[name]) end end diff --git a/libs/module.lua b/libs/module.lua index 6ac86bd..f22a2e4 100644 --- a/libs/module.lua +++ b/libs/module.lua @@ -1,9 +1,12 @@ if getmetatable(getfenv(0)) == false then return end local tinsert, tremove, getn, setn, strfind, type, setmetatable, setfenv, _G = tinsert, tremove, getn, table.setn, strfind, type, setmetatable, setfenv, getfenv(0) -local PUBLIC, FIELD, ACCESSOR, MUTATOR = 1, 2, 4, 6 +local PRIVATE, PUBLIC, FIELD, ACCESSOR, MUTATOR = 0, 1, 2, 4, 6 +local TYPES = { FIELD, ACCESSOR, MUTATOR } local READ, WRITE = '', '=' local OPERATION = { [FIELD]=READ, [ACCESSOR]=READ, [MUTATOR]=WRITE } +local ACCESS = { private=PRIVATE, public=PUBLIC } +local META = { get=ACCESSOR, set=MUTATOR } local function error(msg, ...) return _G.error(format(msg or '', unpack(arg)) .. '\n' .. debugstack(), 0) end @@ -23,30 +26,23 @@ function definition_helper_mt:__index(k) tinsert(_modifiers[self], k) return self end -do - local PUBLIC, META = { public=PUBLIC, private=0 }, { get=ACCESSOR, set=MUTATOR } - function definition_helper_mt:__newindex(k, v) local module, modifiers = _module[self], _modifiers[self] - local public = PUBLIC[tremove(modifiers, 1)] or error('Invalid definition.') - local name = META[k] and (tremove(modifiers) or error('Invalid definition.')) or k - if type(name) ~= 'string' or not strfind(name, '^[_%a][_%w]*') then error('Invalid definition.') end - local type = META[k] or FIELD - module.defined[name..OPERATION[type]] = module.defined[name..OPERATION[type]] and error('"%s" already exists.', name) or true - for i = getn(modifiers), 1, -1 do v = module[FIELD][modifiers[i]](v) end - module[type][name], module[public+type][name] = v, v - setn(modifiers, 0) - end +function definition_helper_mt:__newindex(k, v) local module, modifiers = _module[self], _modifiers[self] + local access = ACCESS[tremove(modifiers, 1)] or error('Invalid definition.') + local name = META[k] and (tremove(modifiers) or error('Invalid definition.')) or k + if type(name) ~= 'string' or not strfind(name, '^[_%a][_%w]*') then error('Invalid definition.') end + local type = META[k] or FIELD + module.defined[name..OPERATION[type]] = module.defined[name..OPERATION[type]] and error('"%s" already exists.', name) or true + for i = getn(modifiers), 1, -1 do v = module[FIELD][modifiers[i]](v) end + module[type][name], module[access+type][name] = v, v + setn(modifiers, 0) end -local import -do - local TYPES = { FIELD, ACCESSOR, MUTATOR } - function import(self, interface) - local module = (interface == INTERFACE or error('Import error.')) and _module[interface] - for _, type in TYPES do - for k, v in module[PUBLIC+type] do - if not self.defined[k..OPERATION[type]] then - self.defined[k..OPERATION[type]], self[type][k] = true, v - end +local function import(self, interface) + local module = (interface == INTERFACE or error('Import error.')) and _module[interface] + for _, type in TYPES do + for k, v in module[PUBLIC+type] do + if not self.defined[k..OPERATION[type]] then + self.defined[k..OPERATION[type]], self[type][k] = true, v end end end @@ -60,7 +56,7 @@ function global_mt:__index(key) local module, environment, interface, definition_helper, accessors, mutators, fields, public_accessors, public_mutators, public_fields environment, interface, definition_helper = {}, {}, setmetatable({}, definition_helper_mt) accessors = { private=function() return definition_helper.private end, public=function() return definition_helper.public end } - mutators = setmetatable({}, { __index=function(_, k) return function(v) if v == interface and (_G[k] == nil or error(nil)) then _G[k] = v end end end}) + mutators = setmetatable({}, { __index=function(_, k) return function(v) if v == interface and (_G[k] == nil or _G.error(nil)) then _G[k] = v else definition_helper.private[k] = v end end end}) fields = setmetatable( { _E=environment, _I=interface, _G=_G, import=function(interface) import(module, interface) end, error=error, nop=nop, id=id }, { __index=function(_, key) local accessor = accessors[key]; if accessor then return accessor() else return _G[key] end end } diff --git a/tabs/post/core.lua b/tabs/post/core.lua index 61d2124..ccd3eee 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -38,12 +38,16 @@ function refresh_button_click() refresh = true end -do local item - selected_item {get=function() return item end, set=function(v) item = v end} +do + local item + function private.selected_item.get() return item end + function private.selected_item.set(v) item = v end end -do local c = 0 - refresh {get=function() return c end, set=function(v) c = v end} +do + local c = 0 + function private.refresh.get() return c end + function private.refresh.set(v) c = v end end function LOAD() diff --git a/tabs/search/results.lua b/tabs/search/results.lua index e7a673a..dd27ccc 100644 --- a/tabs/search/results.lua +++ b/tabs/search/results.lua @@ -4,11 +4,13 @@ _G.aux_auto_buy_filter = '' do local id = 0 - search_scan_id { get=function() return id end, set=function(v) id = v end } + function private.search_scan_id.get() return id end + function private.search_scan_id.set(v) id = v end end do local validator - auto_buy_validator { get=function() return validator end, set=function(v) validator = v end } + function private.auto_buy_validator.get() return validator end + function private.auto_buy_validator.set(v) validator = v end end do diff --git a/util/money.lua b/util/money.lua index 6f836a9..d39332e 100644 --- a/util/money.lua +++ b/util/money.lua @@ -1,10 +1,8 @@ aux 'money' -public() -GOLD_TEXT = '|cffffd70ag|r' -SILVER_TEXT = '|cffc7c7cfs|r' -COPPER_TEXT = '|cffeda55fc|r' -private() +public.GOLD_TEXT = '|cffffd70ag|r' +public.SILVER_TEXT = '|cffc7c7cfs|r' +public.COPPER_TEXT = '|cffeda55fc|r' COPPER_PER_GOLD = 10000 COPPER_PER_SILVER = 100 diff --git a/util/sort.lua b/util/sort.lua index ce72404..648a227 100644 --- a/util/sort.lua +++ b/util/sort.lua @@ -1,10 +1,10 @@ aux 'sorting' -public() +public.EQ = 0 +public.LT = 1 +public.GT = 2 -LT, EQ, GT = t, t, t - -function compare(a, b, desc) +function public.compare(a, b, desc) if a < b then return desc and GT or LT elseif a > b then @@ -14,7 +14,7 @@ function compare(a, b, desc) end end -function multi_lt(xs, ys) +function public.multi_lt(xs, ys) local i = 1 while true do if xs[i] and ys[i] and xs[i] ~= ys[i] then