-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.lua
84 lines (71 loc) · 1.67 KB
/
logger.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
local M = {}
M.E = {
wrongPatternLength = "wrongPatternLength"
}
M.W = {
ignoredOrnament = "ignoredOrnament"
}
M.errors = {}
M.warnings = {}
local function distinctList(values)
local distinct = {}
local res = ""
for i, v in ipairs(values) do
if i == 1 then
res = res .. v
elseif distinct[v] ~= true then
res = res .. ", " .. v
end
distinct[v] = true
end
return res
end
local function valueList(data, field)
local module1 = {}
local module2 = {}
for _, v in ipairs(data) do
if v.module == 1 then
table.insert(module1, v[field])
else
table.insert(module2, v[field])
end
end
local res = " Module 1: " .. distinctList(module1)
if #module2 > 0 then
res = res .. "\n Module 2: " .. distinctList(module2)
end
return res
end
function M.errorLog()
local log = ""
for code, data in pairs(M.errors) do
if code == M.E.wrongPatternLength then
log = log .. "[!] All patterns should have 32 or 64 rows. These patterns have wrong length:\n"
log = log .. valueList(data, "pattern") .. "\n"
end
end
return log
end
function M.warningLog()
local log = ""
for code, data in pairs(M.warnings) do
if code == M.W.ignoredOrnament then
log = log .. "[-] These ornaments are ignored because they don't match the rules:\n"
log = log .. valueList(data, "ornament") .. "\n"
end
end
return log
end
function M.error(code, data)
if M.errors[code] == nil then
M.errors[code] = {}
end
table.insert(M.errors[code], data)
end
function M.warning(code, data)
if M.warnings[code] == nil then
M.warnings[code] = {}
end
table.insert(M.warnings[code], data)
end
return M