refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-09-05 09:08:15 +02:00
parent 9576b9fe31
commit 5fc37fe404
4 changed files with 53 additions and 22 deletions
-1
View File
@@ -125,7 +125,6 @@ do
public.T.get = pseudo_literal'kv'
end
p = T('koo', 1, 5, 'mooo')
do
local body = ''
for i = 2, 100 do
+31
View File
@@ -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
View File
@@ -68,7 +68,7 @@ do
elseif access or nil_error() then self.default_access = access end
self.declaration_access, self.declaration_name = nil, nil
end
DECLARATOR.__tostring = function() return 'NIL' end
DECLARATOR.__tostring = function() return 'nil table' end
end
local function import(self, interface)
@@ -80,19 +80,18 @@ local function import(self, interface)
end
end
setmetatable(_G, {
__index = function(_, key)
if key ~= 'module' then return nil end
local interface, environment, declarator = INTERFACE {}, ENVIRONMENT {}, DECLARATOR {}
local self; self = {
access = {_G=PRIVATE, I=PRIVATE, M=PRIVATE, public=PRIVATE, private=PRIVATE, import=PRIVATE, _=PRIVATE, p=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},
[INDEX] = {public=function() return declarator.public end, private=function() return declarator.private end},
[NEWINDEX] = {p=inspect, _=nop},
declarator = declarator,
}
state[interface], state[environment], state[declarator] = self, self, self
setfenv(2, environment)
return interface
end,
})
local mt = {}; setmetatable(_G, mt)
function mt:__index(key)
if key ~= 'module' then return nil end
local interface, environment, declarator = INTERFACE {}, ENVIRONMENT {}, DECLARATOR {}
self = {
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, error=error, nop=nop},
[INDEX] = {public=function() return declarator.public end, private=function() return declarator.private end},
[NEWINDEX] = {_=nop},
declarator = declarator,
}
state[interface], state[environment], state[declarator] = self, self, self
setfenv(2, environment)
return interface
end