refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-27 12:09:08 +02:00
parent 77caf8c063
commit abcc782daa
2 changed files with 21 additions and 17 deletions
+4 -3
View File
@@ -2,10 +2,11 @@ aux 'tooltip' local info, disenchant, cache, money, history = aux.info, aux.dise
_G.aux_tooltip_value = true _G.aux_tooltip_value = true
local game_tooltip_hooks, game_tooltip_money, inside_hook = t, 0, false local game_tooltip_hooks, game_tooltip_money = t, 0
function LOAD() function LOAD()
do do
local inside_hook = false
for name, f in game_tooltip_hooks do for name, f in game_tooltip_hooks do
local name, f = name, f local name, f = name, f
hook(name, GameTooltip, function(...) temp=arg hook(name, GameTooltip, function(...) temp=arg
@@ -31,8 +32,8 @@ function LOAD()
local result = orig(unpack(arg)) local result = orig(unpack(arg))
local name, _, quality = GetItemInfo(arg[1]) local name, _, quality = GetItemInfo(arg[1])
if not IsShiftKeyDown() and not IsControlKeyDown() and name then if not IsShiftKeyDown() and not IsControlKeyDown() and name then
local _, _, _, hex = GetItemQualityColor(quality) local color_code = select(4, GetItemQualityColor(quality))
local link = hex.. '|H'..arg[1]..'|h['..name..']|h'..FONT_COLOR_CODE_CLOSE local link = color_code.. '|H'..arg[1]..'|h['..name..']|h'..FONT_COLOR_CODE_CLOSE
extend_tooltip(ItemRefTooltip, link, 1) extend_tooltip(ItemRefTooltip, link, 1)
end end
return result return result
+17 -14
View File
@@ -35,31 +35,31 @@ do
function declarator_mt:__index(key) local state=_state[self] function declarator_mt:__index(key) local state=_state[self]
if ACCESS[key] and not state.declaration_access then if ACCESS[key] and not state.declaration_access then
state.declaration_access = ACCESS[key] state.declaration_access = ACCESS[key]
elseif not state.declarator_name or declaration_error() then elseif not state.declaration_name or declaration_error() then
state.declarator_name = key state.declaration_name = key
end end
return self return self
end end
function declarator_mt:__newindex(key, value) local state=_state[self] function declarator_mt:__newindex(key, value) local state=_state[self]
-- if module.access[key] then return end -- if module.access[key] then return end
local type local type
if state.declarator_name then if state.declaration_name then
type = TYPE[key] or declaration_error() type = TYPE[key] or declaration_error()
else else
type = typeof(value) == 'function' and FUNCTION or GETTER type = typeof(value) == 'function' and FUNCTION or GETTER
end end
declare(state, state.declaration_access, key, {[type]=value}) declare(state, state.declaration_access, key, {[type]=value})
state.declaration_access, state.declarator_name = nil, nil state.declaration_access, state.declaration_name = nil, nil
end end
function declarator_mt:__call(value) local state=_state[self] function declarator_mt:__call(value) local state=_state[self]
if state.declarator_name then if state.declaration_name then
local success, f, get, set = pcall(extract, value) local success, f, get, set = pcall(extract, value)
if not success then declaration_error() end if not success then declaration_error() end
declare(state, state.declaration_access, state.declarator_name, {[FUNCTION]=f, [GETTER]=get, [SETTER]=set}) declare(state, state.declaration_access, state.declaration_name, {[FUNCTION]=f, [GETTER]=get, [SETTER]=set})
elseif state.declaration_access or declaration_error() then elseif state.declaration_access or declaration_error() then
state.default_access = state.declaration_access state.default_access = state.declaration_access
end end
state.declaration_access, state.declarator_name = nil, nil state.declaration_access, state.declaration_name = nil, nil
end end
end end
@@ -71,9 +71,12 @@ function env_mt:__index(key) local state=_state[self]
if f then return f else return _G[key] end if f then return f else return _G[key] end
end end
function env_mt:__newindex(key, value) local state=_state[self] function env_mt:__newindex(key, value) local state=_state[self]
if declaration_newindex(state, key, value) then return end if state.access[key] then
local f = state[SETTER][key] local f = state[SETTER][key]
if f then f(value); return end if f then f(value) end
else
return state.declarator[key]
end
end end
local interface_mt = {__metatable=false} local interface_mt = {__metatable=false}
@@ -84,7 +87,7 @@ function interface_mt:__index(key) local state=_state[self]
end end
end end
function interface_mt:__newindex(key, value) local state=_state[self] function interface_mt:__newindex(key, value) local state=_state[self]
if state.access[key] == PUBLIC then (state[SETTER][key] or state[FUNCTION][key])(value) end if state.access[key] == PUBLIC then (state[SETTER][key] or nop)(value) end
end end
function module(...) function module(...)
@@ -96,15 +99,15 @@ function module(...)
setters = {} setters = {}
for i=1,arg.n do for i=1,arg.n do
local module = _state[arg[i] or import_error()] or import_error() local module = _state[arg[i] or import_error()] or import_error()
local import_functions, import_getters, import_setters = module[FUNCTION], module[GETTER], module[SETTER] local module_functions, module_getters, module_setters = module[FUNCTION], module[GETTER], module[SETTER]
for k, v in module.access do for k, v in module.access do
if v == PUBLIC and (not access[k] or import_error()) then if v == PUBLIC and (not access[k] or import_error()) then
functions[k], getters[k], setters[k] = import_functions[k], import_getters[k], import_setters[k] functions[k], getters[k], setters[k] = module_functions[k], module_getters[k], module_setters[k]
access[k] = PRIVATE access[k] = PRIVATE
end end
end end
end end
state = {access=access, [FUNCTION]=functions, [GETTER]=getters, [SETTER]=setters, default_access=PRIVATE} state = {access=access, [FUNCTION]=functions, [GETTER]=getters, [SETTER]=setters, declarator=declarator, default_access=PRIVATE}
_state[declarator], _state[env], _state[interface] = state, state, state _state[declarator], _state[env], _state[interface] = state, state, state
setfenv(2, env) setfenv(2, env)
end end