-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.lua
98 lines (85 loc) · 3.34 KB
/
Main.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
scriptDirectory = arg [0]:gsub ("Main.lua", "")
require (scriptDirectory .. "Globals")
require (scriptDirectory .. "ProcessConfiguration")
require (scriptDirectory .. "ProcessVars")
require (scriptDirectory .. "ProcessHeader")
require (scriptDirectory .. "ProcessObject")
require (scriptDirectory .. "ProcessBindings")
_inputFileName = arg [1]
_outputHeaderFileName = arg [2]
_outputObjectFileName = arg [3]
_outputBindingsObjectFileName = arg [4]
if _inputFileName == nil or _outputHeaderFileName == nil or _outputObjectFileName == nil then
Log ("Incorrect input arguments!\nExpected arguments:\n1th -- input file name,\n"..
"2th -- output header file name,\n3th -- output C++ object file name,\n" ..
"4th (optional) -- output bindings C++ file name,\n" ..
"5th (optional) -- log output file name!");
return 1
end
if arg [5] ~= nil then
printOutputFile = io.open (arg [5], "w+")
Log = function (toPrint)
if toPrint ~= nil then
printOutputFile:write (toPrint .. "\n")
end
end
else
Log = function (toPrint)
print (toPrint)
end
end
Log ("Input scaffold: " .. _inputFileName .. "\nOutput header: " .. _outputHeaderFileName ..
"\nOutput object: " .. _outputObjectFileName)
if _outputBindingsObjectFileName ~= nil then
Log ("Output bindings: " .. _outputBindingsObjectFileName)
end
Log ("WARNING: Currently, only one level Urho3D arrays are supported!")
-- Load files
_headerFile = io.open (_outputHeaderFileName, "w+")
_objectFile = io.open (_outputObjectFileName, "w+")
-- If output binding file name starts with "ASBindGenCommand=", detect it as ASBindGen command name
-- and write ASBindGen comments instead of bindings object.
if _outputBindingsObjectFileName ~= nil and _outputBindingsObjectFileName:find ("ASBindGenCommand=") == 1 then
_asBindGenCommand = _outputBindingsObjectFileName:sub (("ASBindGenCommand="):len () + 1, _outputBindingsObjectFileName:len ())
elseif _outputBindingsObjectFileName ~= nil then
_bindingsFile = io.open (_outputBindingsObjectFileName, "w+")
end
for readedLine in io.lines (_inputFileName) do
if _processMode == "Configuration" then
if readedLine:find ("tab:") == 1 then
ReadTab (readedLine)
elseif readedLine:find ("className:") == 1 then
ReadClassName (readedLine)
else
UpdateProcessMode (readedLine, true)
end
elseif _processMode == "Vars" then
UpdateProcessMode (readedLine, false)
if _processMode == "Vars" and readedLine:len () > 10 then
ReadVar (readedLine)
end
elseif _processMode == "Header" then
UpdateProcessMode (readedLine, false)
if _processMode == "Header" then
ProcessHeaderLine (readedLine)
end
elseif _processMode == "Object" then
UpdateProcessMode (readedLine, false)
if _processMode == "Object" then
ProcessObjectLine (readedLine)
end
elseif _processMode == "Bindings" and _asBindGenCommand == nil and _bindingsFile ~= nil then
UpdateProcessMode (readedLine, false)
if _processMode == "Bindings" then
ProcessBindingsLine (readedLine)
end
end
end
_headerFile:close ()
_objectFile:close ()
if _bindingsFile ~= nil then
_bindingsFile:close ()
end
if printOutputFile ~= nil then
printOutputFile:close ()
end