-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparse_global.lua
More file actions
79 lines (63 loc) · 2.31 KB
/
parse_global.lua
File metadata and controls
79 lines (63 loc) · 2.31 KB
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
-- Config
local UISource = './.wow/wow-ui-source/Interface/'
local luacCommand = 'luac'
local outputFile = './.wow/FrameXMLGlobals.lua'
-- Core
local lfs = require('lfs')
local function findAllFiles(path)
local result = {}
for file in lfs.dir(path) do
local fileType = lfs.attributes(path .. '/' .. file, 'mode')
if fileType == 'file' and string.find(file, '^[^.].+%.lua') then
table.insert(result, file)
elseif fileType == 'directory' then
if file ~= '.' and file ~= '..' and not string.match(file, '^Blizzard_Deprecated') then
local subResult = findAllFiles(path .. '/' .. file)
for _, subFile in ipairs(subResult) do
table.insert(result, file .. '/' .. subFile)
end
end
end
end
return result
end
local function executeCapture(command)
local file = assert(io.popen(command, 'r'))
local str = assert(file:read('*a'))
file:close()
str = string.gsub(str, '^%s+', '')
str = string.gsub(str, '%s+$', '')
return str
end
local function findAllGlobals(output, luac, path, file)
executeCapture(string.format('perl -e \'s/\\xef\\xbb\\xbf//;\' -pi %s/%s', path, file))
local content = executeCapture(string.format('%s -l -p %s/%s', luac, path, file))
for line in string.gmatch(content, '[^\r\n]+') do
if string.match(line, 'SETGLOBAL\t') then
local variable = string.match(line, '\t; (.+)%s*')
output[variable] = true
end
end
return output
end
local fileList = findAllFiles(UISource)
table.sort(fileList)
local currentBranch = executeCapture(string.format('git -C %s branch --show-current', UISource))
print(string.format("Currently generating FrameXML globals for %s", currentBranch))
local destFile = assert(io.open(outputFile, 'w'), "Error opening file " .. outputFile)
local globals = {}
for _, filePath in ipairs(fileList) do
print(string.format("Handling file %s", filePath))
findAllGlobals(globals, luacCommand, UISource, filePath)
end
local output = {}
for var in pairs(globals) do
table.insert(output, var)
end
table.sort(output)
destFile:write('local globals = {\n')
for _, var in ipairs(output) do
destFile:write('\t"' .. var .. '",\n')
end
destFile:write('}\n\nreturn globals\n')
destFile:close()