-
Notifications
You must be signed in to change notification settings - Fork 91
/
globalcheck.lua
executable file
·83 lines (71 loc) · 1.71 KB
/
globalcheck.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
local isOSX = os.getenv("MANPATH") and true or false
local leaks = {}
local results = ""
local function output(msg)
results = results .. "\r\n" .. msg
end
local function scanFile(path)
output(io.popen(string.format("luac -l %s", path)):read("*all"))
end
local function scanFolder(path)
local command
if( isOSX ) then
command = string.format("ls \"%s\"", (path or "./"))
else
command = string.format("dir /B \"%s\"", (path or ""))
end
for file in io.popen(command):lines() do
local extension = string.match(file, "%.([%a%d]+)$")
if( file ~= "" and not extension and file ~= "libs" ) then
if( path ) then
scanFolder(path .. "/" .. file)
else
scanFolder(file)
end
elseif( extension == "lua" and file ~= "localcheck.lua" and file ~= "globalcheck.lua" and not string.match(file, "^localization%.([a-zA-Z]+)%.lua") ) then
if( path ) then
scanFile(path .. "/" .. file)
else
scanFile(file)
end
end
end
end
scanFolder()
if( isOSX ) then
io.popen("unlink luac.out")
else
io.popen("del luac.out")
end
local file = io.open("results.txt", "w")
file:write(tostring(results))
file:flush()
file:close()
local f = io.open("results.txt", "r")
local data = f:read("*all")
function lines(str)
local t = {}
local function helper(line) table.insert(t, line) return "" end
helper((str:gsub("(.-)\r?\n", helper)))
return t
end
local printFile
for _, line in pairs(lines(data)) do
if( string.match(line, "(.+) <(.+)>") ) then
file = line
printFile = nil
end
if( string.match(line, "SETGLOBAL") ) then
if( not printFile ) then
print(file)
printFile = true
end
print(line)
end
end
f:close()
if( isOSX ) then
io.popen("unlink results.txt")
else
io.popen("del results.txt")
end