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
+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,
})