forked from dreamanlan/Cs2Lua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
168 lines (166 loc) · 8.62 KB
/
Program.cs
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using RoslynTool.CsToLua;
namespace RoslynTool
{
partial class Program
{
static int Main(string[] args)
{
try {
string file = "test.cs";
string outputExt = "txt";
List<string> macros = new List<string>();
List<string> ignoredPath = new List<string>();
Dictionary<string, string> refByNames = new Dictionary<string, string>();
Dictionary<string, string> refByPaths = new Dictionary<string, string>();
bool enableInherit = false;
bool outputResult = false;
if (args.Length > 0) {
for (int i = 0; i < args.Length; ++i) {
if (0 == string.Compare(args[i], "-ext", true)) {
if (i < args.Length - 1) {
string arg = args[i + 1];
if (!arg.StartsWith("-")) {
outputExt = arg;
++i;
}
}
} else if (0 == string.Compare(args[i], "-d", true)) {
if (i < args.Length - 1) {
string arg = args[i + 1];
if (!arg.StartsWith("-")) {
macros.Add(arg);
++i;
}
}
} else if (0 == string.Compare(args[i], "-ignorepath", true)) {
if (i < args.Length - 1) {
string arg = args[i + 1];
if (!arg.StartsWith("-")) {
ignoredPath.Add(arg);
++i;
}
}
} else if (0 == string.Compare(args[i], "-src", true)) {
if (i < args.Length - 1) {
string arg = args[i + 1];
if (!arg.StartsWith("-")) {
file = arg;
if (!File.Exists(file)) {
Console.WriteLine("file path not found ! {0}", file);
}
++i;
}
}
} else if (0 == string.Compare(args[i], "-enableinherit", true)) {
enableInherit = true;
} else if (0 == string.Compare(args[i], "-normallua", true)) {
SymbolTable.ForSlua = false;
} else if (0 == string.Compare(args[i], "-slua", true)) {
SymbolTable.ForSlua = true;
} else if (0 == string.Compare(args[i], "-outputresult", true)) {
outputResult = true;
} else if (0 == string.Compare(args[i], "-noautorequire", true)) {
SymbolTable.NoAutoRequire = true;
} else if (0 == string.Compare(args[i], "-luacomponentbystring", true)) {
SymbolTable.LuaComponentByString = true;
} else if (0 == string.Compare(args[i], "-refbyname", true)) {
string name = string.Empty, alias = "global";
if (i < args.Length - 1) {
string arg = args[i + 1];
if (!arg.StartsWith("-")) {
name = arg;
++i;
} else {
continue;
}
} else {
continue;
}
if (i < args.Length - 1) {
string arg = args[i + 1];
if (!arg.StartsWith("-")) {
alias = arg;
++i;
}
}
if (!refByNames.ContainsKey(name)) {
refByNames.Add(name, alias);
} else {
Console.WriteLine("refbyname duplicate, ignored ! {0}={1}", name, alias);
}
} else if (0 == string.Compare(args[i], "-refbypath", true)) {
string path = string.Empty, alias = "global";
if (i < args.Length - 1) {
string arg = args[i + 1];
if (!arg.StartsWith("-")) {
path = arg;
++i;
} else {
continue;
}
} else {
continue;
}
if (i < args.Length - 1) {
string arg = args[i + 1];
if (!arg.StartsWith("-")) {
alias = arg;
++i;
}
}
if (!File.Exists(path)) {
Console.WriteLine("refbypath path not found ! {0}={1}", path, alias);
} else {
if (!refByPaths.ContainsKey(path)) {
refByPaths.Add(path, alias);
} else {
Console.WriteLine("refbypath duplicate, ignored ! {0}={1}", path, alias);
}
}
} else {
file = args[i];
if (!File.Exists(file)) {
Console.WriteLine("file path not found ! {0}", file);
}
break;
}
}
} else {
Console.WriteLine("[Usage]:Cs2Lua [-ext fileext] [-enableinherit] [-normallua/-slua] [-outputresult] [-noautorequire] [-luacomponentbystring] [-d macro] [-ignorepath path] [-refbyname dllname alias] [-refbypath dllpath alias] [-src] csfile|csprojfile");
Console.WriteLine("\twhere:");
Console.WriteLine("\t\tfileext = file externsion, default is txt for unity3d, maybe lua for other usage.");
Console.WriteLine("\t\tmacro = c# macro define, used in your csharp code #if/#elif/#else/#endif etc.");
Console.WriteLine("\t\tdllname = dotnet system assembly name, referenced by your csharp code.");
Console.WriteLine("\t\tdllpath = dotnet assembly path, referenced by your csharp code.");
Console.WriteLine("\t\talias = global for default or some dll toplevel namespace alias, used in your csharp code such as 'extern alias ui;'.");
Console.WriteLine();
if (File.Exists(file)) {
Console.WriteLine("now will process test csharp code test.cs in current directory ...");
Console.WriteLine();
}
}
if (File.Exists(file)) {
return (int)CsToLuaProcessor.Process(file, outputExt, macros, ignoredPath, refByNames, refByPaths, enableInherit, outputResult);
} else {
return (int)ExitCode.FileNotFound;
}
} catch (Exception ex) {
Console.WriteLine("exception:{0}", ex.Message);
Console.WriteLine("{0}", ex.StackTrace);
while (null != ex.InnerException) {
ex = ex.InnerException;
Console.WriteLine("inner exception:{0}", ex.Message);
Console.WriteLine("{0}", ex.StackTrace);
}
return (int)ExitCode.Exception;
}
}
}
}