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.cs38
1 files changed, 18 insertions, 20 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
index a2eee66..7f452e0 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
@@ -27,16 +27,13 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic;
31using System.Text;
32using System.IO;
33using Microsoft.CSharp;
34using System.CodeDom.Compiler; 30using System.CodeDom.Compiler;
31using System.IO;
35using System.Reflection; 32using System.Reflection;
33using Microsoft.CSharp;
36 34
37namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL 35namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
38{ 36{
39
40 public class Compiler 37 public class Compiler
41 { 38 {
42 private LSL2CSConverter LSL_Converter = new LSL2CSConverter(); 39 private LSL2CSConverter LSL_Converter = new LSL2CSConverter();
@@ -45,7 +42,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
45 //private ICodeCompiler icc = codeProvider.CreateCompiler(); 42 //private ICodeCompiler icc = codeProvider.CreateCompiler();
46 public string CompileFromFile(string LSOFileName) 43 public string CompileFromFile(string LSOFileName)
47 { 44 {
48 switch (System.IO.Path.GetExtension(LSOFileName).ToLower()) 45 switch (Path.GetExtension(LSOFileName).ToLower())
49 { 46 {
50 case ".txt": 47 case ".txt":
51 case ".lsl": 48 case ".lsl":
@@ -58,6 +55,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
58 throw new Exception("Unknown script type."); 55 throw new Exception("Unknown script type.");
59 } 56 }
60 } 57 }
58
61 /// <summary> 59 /// <summary>
62 /// Converts script from LSL to CS and calls CompileFromCSText 60 /// Converts script from LSL to CS and calls CompileFromCSText
63 /// </summary> 61 /// </summary>
@@ -67,13 +65,14 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
67 { 65 {
68 if (Script.Substring(0, 4).ToLower() == "//c#") 66 if (Script.Substring(0, 4).ToLower() == "//c#")
69 { 67 {
70 return CompileFromCSText( Script ); 68 return CompileFromCSText(Script);
71 } 69 }
72 else 70 else
73 { 71 {
74 return CompileFromCSText(LSL_Converter.Convert(Script)); 72 return CompileFromCSText(LSL_Converter.Convert(Script));
75 } 73 }
76 } 74 }
75
77 /// <summary> 76 /// <summary>
78 /// Compile CS script to .Net assembly (.dll) 77 /// Compile CS script to .Net assembly (.dll)
79 /// </summary> 78 /// </summary>
@@ -81,14 +80,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
81 /// <returns>Filename to .dll assembly</returns> 80 /// <returns>Filename to .dll assembly</returns>
82 public string CompileFromCSText(string Script) 81 public string CompileFromCSText(string Script)
83 { 82 {
84
85
86 // Output assembly name 83 // Output assembly name
87 scriptCompileCounter++; 84 scriptCompileCounter++;
88 string OutFile = Path.Combine("ScriptEngines", "Script_" + scriptCompileCounter + ".dll"); 85 string OutFile = Path.Combine("ScriptEngines", "Script_" + scriptCompileCounter + ".dll");
89 try 86 try
90 { 87 {
91 System.IO.File.Delete(OutFile); 88 File.Delete(OutFile);
92 } 89 }
93 catch (Exception e) 90 catch (Exception e)
94 { 91 {
@@ -99,12 +96,15 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
99 // DEBUG - write source to disk 96 // DEBUG - write source to disk
100 try 97 try
101 { 98 {
102 File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script); 99 File.WriteAllText(
100 Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script);
101 }
102 catch
103 {
103 } 104 }
104 catch { }
105 105
106 // Do actual compile 106 // Do actual compile
107 System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters(); 107 CompilerParameters parameters = new CompilerParameters();
108 parameters.IncludeDebugInformation = true; 108 parameters.IncludeDebugInformation = true;
109 // Add all available assemblies 109 // Add all available assemblies
110 foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) 110 foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
@@ -114,11 +114,11 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
114 } 114 }
115 115
116 string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); 116 string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
117 string rootPathSE = Path.GetDirectoryName(this.GetType().Assembly.Location); 117 string rootPathSE = Path.GetDirectoryName(GetType().Assembly.Location);
118 //Console.WriteLine("Assembly location: " + rootPath); 118 //Console.WriteLine("Assembly location: " + rootPath);
119 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Common.dll")); 119 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Common.dll"));
120 parameters.ReferencedAssemblies.Add(Path.Combine(rootPathSE, "OpenSim.Region.ScriptEngine.DotNetEngine.dll")); 120 parameters.ReferencedAssemblies.Add(Path.Combine(rootPathSE, "OpenSim.Region.ScriptEngine.DotNetEngine.dll"));
121 121
122 //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment"); 122 //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment");
123 parameters.GenerateExecutable = false; 123 parameters.GenerateExecutable = false;
124 parameters.OutputAssembly = OutFile; 124 parameters.OutputAssembly = OutFile;
@@ -129,13 +129,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
129 // TODO: Return errors to user somehow 129 // TODO: Return errors to user somehow
130 if (results.Errors.Count > 0) 130 if (results.Errors.Count > 0)
131 { 131 {
132
133 string errtext = ""; 132 string errtext = "";
134 foreach (CompilerError CompErr in results.Errors) 133 foreach (CompilerError CompErr in results.Errors)
135 { 134 {
136 errtext += "Line number " + (CompErr.Line - 1) + 135 errtext += "Line number " + (CompErr.Line - 1) +
137 ", Error Number: " + CompErr.ErrorNumber + 136 ", Error Number: " + CompErr.ErrorNumber +
138 ", '" + CompErr.ErrorText + "'\r\n"; 137 ", '" + CompErr.ErrorText + "'\r\n";
139 } 138 }
140 throw new Exception(errtext); 139 throw new Exception(errtext);
141 } 140 }
@@ -143,6 +142,5 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
143 142
144 return OutFile; 143 return OutFile;
145 } 144 }
146
147 } 145 }
148} 146} \ No newline at end of file