-
Notifications
You must be signed in to change notification settings - Fork 1
/
syntaxcheck.lua
60 lines (49 loc) · 1.33 KB
/
syntaxcheck.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
local function identifyOS()
return package.config:sub(1, 1) == "\\" and "WIN32" or "UNIX"
end
local includePath = debug.getinfo(1).source:gsub("^@", ""):gsub("\\syntaxcheck%.lua$", "")
local osName = identifyOS()
local tforeach = table.foreach or function(tbl, func)
for k, v in next, tbl do
func(k, v)
end
end
if osName == "WIN32" then
local function dir(params)
local proc = io.popen("dir /B " .. params .. " 2>nul")
local ret = {}
for line in proc:lines() do
table.insert(ret, line)
end
proc:close()
return ret
end
local function getFiles(path)
return dir("/A-H-D " .. path)
end
local function getFolders(path)
return dir("/A-HD " .. path)
end
local function findAllFiles(path, extension, ret)
ret = ret or {}
for _, folder in next, getFolders(path) do
findAllFiles(path .. "\\" .. folder, extension, ret)
end
for _, file in next, getFiles(path) do
if file:match("%." .. extension .. "$") then
table.insert(ret, path .. "\\" .. file)
end
end
return ret
end
tforeach(findAllFiles(includePath, "lua"), function(k, file)
print("Checking", file)
local res, err = loadfile(file)
if not res then
print(err)
local line = tonumber(err:match(":(%d+):"))
os.execute(([[start "" "C:\Program Files (x86)\Notepad++\notepad++.exe" -n%i %s]]):format(line, file))
end
end)
end
os.exit(0)