aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs45
1 files changed, 45 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
new file mode 100644
index 0000000..b5a4a39
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
@@ -0,0 +1,45 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using Microsoft.CSharp;
6using System.CodeDom.Compiler;
7
8namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
9{
10 class Compiler
11 {
12 private LSL2CS.Converter.LSL2CSConverter LSL_Converter = new LSL2CS.Converter.LSL2CSConverter();
13 private CSharpCodeProvider codeProvider = new CSharpCodeProvider();
14 //private ICodeCompiler icc = codeProvider.CreateCompiler();
15 public string Compile(string LSOFileName)
16 {
17
18
19 string OutFile = Path.GetFileNameWithoutExtension(LSOFileName);
20
21 // TODO: Add error handling
22 string CS_Code = LSL_Converter.Convert(File.ReadAllText(LSOFileName));
23
24 System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
25 parameters.GenerateExecutable = true;
26 parameters.OutputAssembly = OutFile;
27 CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, CS_Code);
28
29 // TODO: Return errors to user somehow
30 if (results.Errors.Count > 0)
31 {
32 foreach (CompilerError CompErr in results.Errors)
33 {
34 Console.WriteLine("Line number " + CompErr.Line +
35 ", Error Number: " + CompErr.ErrorNumber +
36 ", '" + CompErr.ErrorText + ";");
37 }
38 }
39
40
41 return OutFile;
42 }
43
44 }
45}