refactoring
This commit is contained in:
+6
-4
@@ -9,6 +9,7 @@ do local modules = {}
|
|||||||
modules[name] = module and M
|
modules[name] = module and M
|
||||||
import (green_t)
|
import (green_t)
|
||||||
private.aux = setmetatable(t, mt)
|
private.aux = setmetatable(t, mt)
|
||||||
|
private.p.set = inspect
|
||||||
end)()
|
end)()
|
||||||
end
|
end
|
||||||
modules[name].import (modules.core.I)
|
modules[name].import (modules.core.I)
|
||||||
@@ -32,6 +33,7 @@ local current_owner_page
|
|||||||
function public.current_owner_page.get() return current_owner_page end
|
function public.current_owner_page.get() return current_owner_page end
|
||||||
|
|
||||||
local event_frame = CreateFrame('Frame')
|
local event_frame = CreateFrame('Frame')
|
||||||
|
|
||||||
for event in temp-S('ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE') do
|
for event in temp-S('ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', '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
|
||||||
@@ -39,13 +41,13 @@ end
|
|||||||
ADDON_LOADED = t
|
ADDON_LOADED = t
|
||||||
do
|
do
|
||||||
local handlers, handlers2 = t, t
|
local handlers, handlers2 = t, t
|
||||||
function public.LOAD.set(f) handlers[f] = true end
|
function public.LOAD.set(f) tinsert(handlers, f) end
|
||||||
function public.LOAD2.set(f) handlers2[f] = true end
|
function public.LOAD2.set(f) handlers2[f] = true end
|
||||||
event_frame:SetScript('OnEvent', function()
|
event_frame:SetScript('OnEvent', function()
|
||||||
if event == 'ADDON_LOADED' then
|
if event == 'ADDON_LOADED' then
|
||||||
(ADDON_LOADED[arg1] or nop)()
|
(ADDON_LOADED[arg1] or nop)()
|
||||||
elseif event == 'VARIABLES_LOADED' then
|
elseif event == 'VARIABLES_LOADED' then
|
||||||
for f in handlers do f() end
|
for _, f in handlers do f() end
|
||||||
elseif event == 'PLAYER_LOGIN' then
|
elseif event == 'PLAYER_LOGIN' then
|
||||||
for f in handlers2 do f() end
|
for f in handlers2 do f() end
|
||||||
print('v' .. version .. ' loaded.')
|
print('v' .. version .. ' loaded.')
|
||||||
@@ -151,7 +153,7 @@ end
|
|||||||
|
|
||||||
function public.is_player(name, current)
|
function public.is_player(name, current)
|
||||||
local realm = GetCVar('realmName')
|
local realm = GetCVar('realmName')
|
||||||
return not current and index(_G.aux_characters, realm, name) or UnitName 'player' == name
|
return not current and index(_G.aux_characters, realm, name) or UnitName('player') == name
|
||||||
end
|
end
|
||||||
|
|
||||||
function public.neutral_faction()
|
function public.neutral_faction()
|
||||||
@@ -269,6 +271,6 @@ end
|
|||||||
|
|
||||||
function AuctionFrameAuctions_OnEvent(...) temp=arg
|
function AuctionFrameAuctions_OnEvent(...) temp=arg
|
||||||
if AuctionFrameAuctions:IsVisible() then
|
if AuctionFrameAuctions:IsVisible() then
|
||||||
return orig.AuctionFrameAuctions_OnEvent(unpack(arg))
|
return orig.AuctionFrameAuctions_OnEvent(unpack(arg))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -125,7 +125,6 @@ do
|
|||||||
public.T.get = pseudo_literal'kv'
|
public.T.get = pseudo_literal'kv'
|
||||||
end
|
end
|
||||||
|
|
||||||
p = T('koo', 1, 5, 'mooo')
|
|
||||||
do
|
do
|
||||||
local body = ''
|
local body = ''
|
||||||
for i = 2, 100 do
|
for i = 2, 100 do
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
local function print(msg)
|
||||||
|
DEFAULT_CHAT_FRAME:AddMessage(RED_FONT_COLOR_CODE .. msg)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function format_key(k)
|
||||||
|
return type(k) == 'string' and k or '[' .. tostring(k) .. ']'
|
||||||
|
end
|
||||||
|
local function format_value(v)
|
||||||
|
return type(v) == 'string' and '"' .. v .. '"' or tostring(v)
|
||||||
|
end
|
||||||
|
|
||||||
|
function inspect(...)
|
||||||
|
for i = 1, arg.n do
|
||||||
|
print('arg' .. i..' = ' .. format_value(arg[i]))
|
||||||
|
if type(arg[i]) == 'table' and next(arg[i]) then
|
||||||
|
print('{')
|
||||||
|
for k, v in arg[i] do
|
||||||
|
print(' ' .. format_key(k) .. ' = ' .. format_value(v))
|
||||||
|
end
|
||||||
|
print('}')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return unpack(arg)
|
||||||
|
end
|
||||||
|
|
||||||
|
p = setmetatable({}, {
|
||||||
|
__metatable = false,
|
||||||
|
__pow = function(self, v) self(v); return v end,
|
||||||
|
__sub = function(self, v) self(v); return v end,
|
||||||
|
__call = function(_, ...) return inspect(unpack(arg)) end,
|
||||||
|
})
|
||||||
+16
-17
@@ -68,7 +68,7 @@ do
|
|||||||
elseif access or nil_error() then self.default_access = access end
|
elseif access or nil_error() then self.default_access = access end
|
||||||
self.declaration_access, self.declaration_name = nil, nil
|
self.declaration_access, self.declaration_name = nil, nil
|
||||||
end
|
end
|
||||||
DECLARATOR.__tostring = function() return 'NIL' end
|
DECLARATOR.__tostring = function() return 'nil table' end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function import(self, interface)
|
local function import(self, interface)
|
||||||
@@ -80,19 +80,18 @@ local function import(self, interface)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(_G, {
|
local mt = {}; setmetatable(_G, mt)
|
||||||
__index = function(_, key)
|
function mt:__index(key)
|
||||||
if key ~= 'module' then return nil end
|
if key ~= 'module' then return nil end
|
||||||
local interface, environment, declarator = INTERFACE {}, ENVIRONMENT {}, DECLARATOR {}
|
local interface, environment, declarator = INTERFACE {}, ENVIRONMENT {}, DECLARATOR {}
|
||||||
local self; self = {
|
self = {
|
||||||
access = {_G=PRIVATE, I=PRIVATE, M=PRIVATE, public=PRIVATE, private=PRIVATE, import=PRIVATE, _=PRIVATE, p=PRIVATE, error=PRIVATE, nop=PRIVATE},
|
access = {_G=PRIVATE, I=PRIVATE, M=PRIVATE, public=PRIVATE, private=PRIVATE, import=PRIVATE, _=PRIVATE, error=PRIVATE, nop=PRIVATE},
|
||||||
[CALL] = {_G=_G, I=interface, M=environment, import=function(interface) import(self, interface) end, p=inspect, error=error, nop=nop},
|
[CALL] = {_G=_G, I=interface, M=environment, import=function(interface) import(self, interface) end, error=error, nop=nop},
|
||||||
[INDEX] = {public=function() return declarator.public end, private=function() return declarator.private end},
|
[INDEX] = {public=function() return declarator.public end, private=function() return declarator.private end},
|
||||||
[NEWINDEX] = {p=inspect, _=nop},
|
[NEWINDEX] = {_=nop},
|
||||||
declarator = declarator,
|
declarator = declarator,
|
||||||
}
|
}
|
||||||
state[interface], state[environment], state[declarator] = self, self, self
|
state[interface], state[environment], state[declarator] = self, self, self
|
||||||
setfenv(2, environment)
|
setfenv(2, environment)
|
||||||
return interface
|
return interface
|
||||||
end,
|
end
|
||||||
})
|
|
||||||
Reference in New Issue
Block a user