From abcc782daa8a7b4805ebbc5640ae934dbb3bb9d4 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Sat, 27 Aug 2016 12:09:08 +0200 Subject: [PATCH] refactoring --- core/tooltip.lua | 7 ++++--- libs/module.lua | 31 +++++++++++++++++-------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/core/tooltip.lua b/core/tooltip.lua index c584bb7..f5bbb0a 100644 --- a/core/tooltip.lua +++ b/core/tooltip.lua @@ -2,10 +2,11 @@ aux 'tooltip' local info, disenchant, cache, money, history = aux.info, aux.dise _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() do + local inside_hook = false for name, f in game_tooltip_hooks do local name, f = name, f hook(name, GameTooltip, function(...) temp=arg @@ -31,8 +32,8 @@ function LOAD() local result = orig(unpack(arg)) local name, _, quality = GetItemInfo(arg[1]) if not IsShiftKeyDown() and not IsControlKeyDown() and name then - local _, _, _, hex = GetItemQualityColor(quality) - local link = hex.. '|H'..arg[1]..'|h['..name..']|h'..FONT_COLOR_CODE_CLOSE + local color_code = select(4, GetItemQualityColor(quality)) + local link = color_code.. '|H'..arg[1]..'|h['..name..']|h'..FONT_COLOR_CODE_CLOSE extend_tooltip(ItemRefTooltip, link, 1) end return result diff --git a/libs/module.lua b/libs/module.lua index 941b4c6..e551de9 100644 --- a/libs/module.lua +++ b/libs/module.lua @@ -35,31 +35,31 @@ do function declarator_mt:__index(key) local state=_state[self] if ACCESS[key] and not state.declaration_access then state.declaration_access = ACCESS[key] - elseif not state.declarator_name or declaration_error() then - state.declarator_name = key + elseif not state.declaration_name or declaration_error() then + state.declaration_name = key end return self end function declarator_mt:__newindex(key, value) local state=_state[self] -- if module.access[key] then return end local type - if state.declarator_name then + if state.declaration_name then type = TYPE[key] or declaration_error() else type = typeof(value) == 'function' and FUNCTION or GETTER end 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 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) 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 state.default_access = state.declaration_access end - state.declaration_access, state.declarator_name = nil, nil + state.declaration_access, state.declaration_name = nil, nil 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 end function env_mt:__newindex(key, value) local state=_state[self] - if declaration_newindex(state, key, value) then return end - local f = state[SETTER][key] - if f then f(value); return end + if state.access[key] then + local f = state[SETTER][key] + if f then f(value) end + else + return state.declarator[key] + end end local interface_mt = {__metatable=false} @@ -84,7 +87,7 @@ function interface_mt:__index(key) local state=_state[self] end end 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 function module(...) @@ -96,15 +99,15 @@ function module(...) setters = {} for i=1,arg.n do 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 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 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 setfenv(2, env) end \ No newline at end of file