public static int Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Usage: luac <file> [outfile]"); Console.WriteLine(" <file> is the input file name"); Console.WriteLine(" [outfile] is an optional output file name"); return 1; } Parser.Parser p = new SharpLua.Parser.Parser(); bool success; Chunk c = p.ParseChunk(new Parser.TextInput(File.ReadAllText(args[0])), out success); if (success) { string _out = ""; if (args.Length > 1) _out = args[1]; else _out = Path.GetDirectoryName(args[0]) + "\\" + Path.GetFileNameWithoutExtension(args[0]) + ".sluac"; SharpLua.Serializer.Serialize(c, _out); return 0; } else { Console.WriteLine("Parsing error(s)!"); foreach (Tuple<int, string> t in p.Errors) Console.WriteLine("Line " + t.Item1 + ": " + t.Item2); } return 1; }
public static int Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Usage: luac <file> [outfile]"); Console.WriteLine(" <file> is the input file name"); Console.WriteLine(" [outfile] is an optional output file name"); return(1); } Parser.Parser p = new SharpLua.Parser.Parser(); bool success; Chunk c = p.ParseChunk(new Parser.TextInput(File.ReadAllText(args[0])), out success); if (success) { string _out = ""; if (args.Length > 1) { _out = args[1]; } else { _out = Path.GetDirectoryName(args[0]) + "\\" + Path.GetFileNameWithoutExtension(args[0]) + ".sluac"; } SharpLua.Serializer.Serialize(c, _out); return(0); } else { Console.WriteLine("Parsing error(s)!"); foreach (Tuple <int, string> t in p.Errors) { Console.WriteLine("Line " + t.Item1 + ": " + t.Item2); } } return(1); }
public static CompilerResults Compile(string[] filenames, OutputType ot, string outfile) { //Generate Parameters and Code Provider Microsoft.CSharp.CSharpCodeProvider csharp = new Microsoft.CSharp.CSharpCodeProvider(); CompilerParameters param = new CompilerParameters(); param.GenerateInMemory = false; param.IncludeDebugInformation = true; param.GenerateExecutable = ot == OutputType.Dll ? false : true; param.OutputAssembly = outfile; param.EmbeddedResources.Add("SharpLua.dll"); param.ReferencedAssemblies.Add("SharpLua.dll"); string classname2 = (new System.Random(DateTime.Now.Millisecond)).Next().ToString(); switch (ot) { case OutputType.Dll: param.CompilerOptions = "/target:library"; break; case OutputType.Exe: param.CompilerOptions = "/target:exe"; break; case OutputType.WinFormsExe: param.CompilerOptions = "/target:winexe"; break; default: param.CompilerOptions = "/target:exe"; break; } param.MainClass = "SharpLua.ClassName" + classname2; // Generate SharpLua Code string SharpLuaScript = GetLSScript(); SharpLuaScript = SharpLuaScript.Replace("{ClassName}", "ClassName" + classname2); string ActualSharpLuaCode = ""; foreach (string filename in filenames) { try { ActualSharpLuaCode += System.IO.File.ReadAllText(filename); } catch { } // Attempt basic parsing. try { Parser.Parser p = new SharpLua.Parser.Parser(); bool s; p.ParseChunk(new Parser.TextInput(ActualSharpLuaCode), out s); } catch (Exception e) { Console.WriteLine("Parsing Error: " + e.ToString()); return(null); } // Compiling ActualSharpLuaCode = ActualSharpLuaCode.Replace("\\", "\\\\"); ActualSharpLuaCode = ActualSharpLuaCode.Replace("\"", "\\\""); string[] codes = ActualSharpLuaCode.Split(new string[] { "\n" }, StringSplitOptions.None); string newcodes = ""; for (int i = 0; i < codes.Length; i++) { newcodes += "\"" + codes[i].Replace("\n", "").Replace("\r", "") + "\","; } if (newcodes.EndsWith(",")) { newcodes = newcodes.Substring(0, newcodes.Length - 1); } SharpLuaScript = SharpLuaScript.Replace("|insertcodehere|", newcodes); System.IO.File.WriteAllText(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filename), System.IO.Path.GetFileNameWithoutExtension(filename) + ".cs"), SharpLuaScript); } // Compile and return the results CompilerResults results = csharp.CompileAssemblyFromSource(param, SharpLuaScript); return(results); }
public static CompilerResults Compile(string[] filenames, OutputType ot, string outfile) { //Generate Parameters and Code Provider Microsoft.CSharp.CSharpCodeProvider csharp = new Microsoft.CSharp.CSharpCodeProvider(); CompilerParameters param = new CompilerParameters(); param.GenerateInMemory = false; param.IncludeDebugInformation = true; param.GenerateExecutable=ot == OutputType.Dll ? false : true; param.OutputAssembly = outfile; param.EmbeddedResources.Add("SharpLua.dll"); param.ReferencedAssemblies.Add("SharpLua.dll"); string classname2 =(new System.Random(DateTime.Now.Millisecond)).Next().ToString(); switch (ot) { case OutputType.Dll: param.CompilerOptions = "/target:library"; break; case OutputType.Exe: param.CompilerOptions = "/target:exe"; break; case OutputType.WinFormsExe: param.CompilerOptions = "/target:winexe"; break; default: param.CompilerOptions = "/target:exe"; break; } param.MainClass = "SharpLua.ClassName" + classname2; // Generate SharpLua Code string SharpLuaScript = GetLSScript(); SharpLuaScript = SharpLuaScript.Replace("{ClassName}", "ClassName" + classname2); string ActualSharpLuaCode =""; foreach (string filename in filenames) { try { ActualSharpLuaCode += System.IO.File.ReadAllText(filename); } catch { } // Attempt basic parsing. try { Parser.Parser p = new SharpLua.Parser.Parser(); bool s; p.ParseChunk(new Parser.TextInput(ActualSharpLuaCode), out s); } catch (Exception e) { Console.WriteLine("Parsing Error: " + e.ToString()); return null; } // Compiling ActualSharpLuaCode = ActualSharpLuaCode.Replace("\\", "\\\\"); ActualSharpLuaCode = ActualSharpLuaCode.Replace("\"", "\\\""); string[] codes = ActualSharpLuaCode.Split(new string[] {"\n"}, StringSplitOptions.None); string newcodes = ""; for (int i = 0; i < codes.Length; i++) newcodes += "\"" + codes[i].Replace("\n","").Replace("\r","") + "\","; if (newcodes.EndsWith(",")) newcodes = newcodes.Substring(0, newcodes.Length -1); SharpLuaScript = SharpLuaScript.Replace("|insertcodehere|", newcodes); System.IO.File.WriteAllText(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filename), System.IO.Path.GetFileNameWithoutExtension(filename) + ".cs"), SharpLuaScript); } // Compile and return the results CompilerResults results= csharp.CompileAssemblyFromSource(param, SharpLuaScript); return results; }