refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-27 23:53:50 +02:00
parent 29b6a81d95
commit 23d88e7d82
3 changed files with 12 additions and 10 deletions
+3 -2
View File
@@ -161,11 +161,12 @@ 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)
public()
_=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()
_=private
end
function public.log(...) temp=arg
+2 -1
View File
@@ -56,7 +56,8 @@ function extend_tooltip(tooltip, link, quantity)
tooltip:AddLine(format('Can disenchant from level %s |cff1eff00Uncommon|r items.', range), color.r, color.g, color.b, true)
end
end
for item_info in present(info.item(item_id)) do
local item_info = info.item(item_id)
if item_info then
local distribution = disenchant.distribution(item_info.slot, item_info.quality, item_info.level)
if getn(distribution) > 0 then
if _G.aux_tooltip_disenchant_distribution then
+7 -7
View File
@@ -5,8 +5,8 @@ local PUBLIC, PRIVATE = 1, 2
local FUNCTION, GETTER, SETTER = 1, 2, 3
local function error(msg, ...) return _G.error(format(msg or '', unpack(arg))..'\n'..debugstack(), 0) end
local function import_error() error 'Invalid imports.' end
local function declaration_error() error 'Invalid declaration.' end
local function import_error(details) error('Import error'..(details and ': '..details or '')..'.') end
local function declaration_error(details) error('Declaration error'..(details and ': '..details or '')..'.') end
local function collision_error(key) error('"%s" already exists.', key) end
local function nop() end
@@ -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 or declaration_error()
state.access[name] = state.access[name] and collision_error(name) or access or state.default_access
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)
@@ -70,8 +70,8 @@ function env_mt:__index(key) local state=_state[self]
end
function env_mt:__newindex(key, value) local state=_state[self]
if state.access[key] then
local setter = state[SETTER][key]
if setter then setter(value) end
local setter = state[SETTER][key] or collision_error(key)
setter(value)
else
state.declarator[key] = value
end
@@ -91,10 +91,10 @@ end
function module(...)
local state, declarator, env, interface, access, functions, getters, setters
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}
access = {_=PRIVATE, 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}
setters = {}
setters = {_=nop}
for i=1,arg.n do
local module = _state[arg[i] or import_error()] or import_error()
local module_functions, module_getters, module_setters = module[FUNCTION], module[GETTER], module[SETTER]