aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
authorlbsa712007-09-14 09:25:07 +0000
committerlbsa712007-09-14 09:25:07 +0000
commit1b1808d45db249dbc9a82ca60dfdc852f51e958c (patch)
treed2b0172e2ee23332e01816a1ca16e7e88da2a809 /OpenSim/Region/ScriptEngine
parentmore fun with LSL implementations (diff)
downloadopensim-SC_OLD-1b1808d45db249dbc9a82ca60dfdc852f51e958c.zip
opensim-SC_OLD-1b1808d45db249dbc9a82ca60dfdc852f51e958c.tar.gz
opensim-SC_OLD-1b1808d45db249dbc9a82ca60dfdc852f51e958c.tar.bz2
opensim-SC_OLD-1b1808d45db249dbc9a82ca60dfdc852f51e958c.tar.xz
* fixed script compilation
* reversed //c# - if * rightifyed what's actually converted
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs226
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/c_sharp_example.txt12
2 files changed, 125 insertions, 113 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
index bbfd097..78cfd21 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
@@ -1,120 +1,120 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Text; 3using System.Text;
4using System.IO; 4using System.IO;
5using Microsoft.CSharp; 5using Microsoft.CSharp;
6using System.CodeDom.Compiler; 6using System.CodeDom.Compiler;
7using System.Reflection; 7using System.Reflection;
8 8
9namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL 9namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
10{ 10{
11 11
12 public class Compiler 12 public class Compiler
13 { 13 {
14 private LSL2CSConverter LSL_Converter = new LSL2CSConverter(); 14 private LSL2CSConverter LSL_Converter = new LSL2CSConverter();
15 private CSharpCodeProvider codeProvider = new CSharpCodeProvider(); 15 private CSharpCodeProvider codeProvider = new CSharpCodeProvider();
16 private static UInt64 scriptCompileCounter = 0; 16 private static UInt64 scriptCompileCounter = 0;
17 //private ICodeCompiler icc = codeProvider.CreateCompiler(); 17 //private ICodeCompiler icc = codeProvider.CreateCompiler();
18 public string CompileFromFile(string LSOFileName) 18 public string CompileFromFile(string LSOFileName)
19 { 19 {
20 switch (System.IO.Path.GetExtension(LSOFileName).ToLower()) 20 switch (System.IO.Path.GetExtension(LSOFileName).ToLower())
21 { 21 {
22 case ".txt": 22 case ".txt":
23 case ".lsl": 23 case ".lsl":
24 Common.SendToDebug("Source code is LSL, converting to CS"); 24 Common.SendToDebug("Source code is LSL, converting to CS");
25 return CompileFromLSLText(File.ReadAllText(LSOFileName)); 25 return CompileFromLSLText(File.ReadAllText(LSOFileName));
26 case ".cs": 26 case ".cs":
27 Common.SendToDebug("Source code is CS"); 27 Common.SendToDebug("Source code is CS");
28 return CompileFromCSText(File.ReadAllText(LSOFileName)); 28 return CompileFromCSText(File.ReadAllText(LSOFileName));
29 default: 29 default:
30 throw new Exception("Unknown script type."); 30 throw new Exception("Unknown script type.");
31 } 31 }
32 } 32 }
33 /// <summary> 33 /// <summary>
34 /// Converts script from LSL to CS and calls CompileFromCSText 34 /// Converts script from LSL to CS and calls CompileFromCSText
35 /// </summary> 35 /// </summary>
36 /// <param name="Script">LSL script</param> 36 /// <param name="Script">LSL script</param>
37 /// <returns>Filename to .dll assembly</returns> 37 /// <returns>Filename to .dll assembly</returns>
38 public string CompileFromLSLText(string Script) 38 public string CompileFromLSLText(string Script)
39 { 39 {
40 if (Script.Substring(0, 4).ToLower() == "//c#") 40 if (Script.Substring(0, 4).ToLower() == "//c#")
41 { 41 {
42 return LSL_Converter.Convert(Script); 42 return CompileFromCSText( Script );
43 } 43 }
44 else 44 else
45 { 45 {
46 return CompileFromCSText(LSL_Converter.Convert(Script)); 46 return CompileFromCSText(LSL_Converter.Convert(Script));
47 } 47 }
48 } 48 }
49 /// <summary> 49 /// <summary>
50 /// Compile CS script to .Net assembly (.dll) 50 /// Compile CS script to .Net assembly (.dll)
51 /// </summary> 51 /// </summary>
52 /// <param name="Script">CS script</param> 52 /// <param name="Script">CS script</param>
53 /// <returns>Filename to .dll assembly</returns> 53 /// <returns>Filename to .dll assembly</returns>
54 public string CompileFromCSText(string Script) 54 public string CompileFromCSText(string Script)
55 { 55 {
56 56
57 57
58 // Output assembly name 58 // Output assembly name
59 scriptCompileCounter++; 59 scriptCompileCounter++;
60 string OutFile = Path.Combine("ScriptEngines", "Script_" + scriptCompileCounter + ".dll"); 60 string OutFile = Path.Combine("ScriptEngines", "Script_" + scriptCompileCounter + ".dll");
61 try 61 try
62 { 62 {
63 System.IO.File.Delete(OutFile); 63 System.IO.File.Delete(OutFile);
64 } 64 }
65 catch (Exception e) 65 catch (Exception e)
66 { 66 {
67 Console.WriteLine("Exception attempting to delete old compiled script: " + e.ToString()); 67 Console.WriteLine("Exception attempting to delete old compiled script: " + e.ToString());
68 } 68 }
69 //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll"); 69 //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll");
70 70
71 // DEBUG - write source to disk 71 // DEBUG - write source to disk
72 try 72 try
73 { 73 {
74 File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script); 74 File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script);
75 } 75 }
76 catch { } 76 catch { }
77 77
78 // Do actual compile 78 // Do actual compile
79 System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters(); 79 System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
80 parameters.IncludeDebugInformation = true; 80 parameters.IncludeDebugInformation = true;
81 // Add all available assemblies 81 // Add all available assemblies
82 foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) 82 foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
83 { 83 {
84 //Console.WriteLine("Adding assembly: " + asm.Location); 84 //Console.WriteLine("Adding assembly: " + asm.Location);
85 //parameters.ReferencedAssemblies.Add(asm.Location); 85 //parameters.ReferencedAssemblies.Add(asm.Location);
86 } 86 }
87 87
88 string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); 88 string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
89 string rootPathSE = Path.GetDirectoryName(this.GetType().Assembly.Location); 89 string rootPathSE = Path.GetDirectoryName(this.GetType().Assembly.Location);
90 //Console.WriteLine("Assembly location: " + rootPath); 90 //Console.WriteLine("Assembly location: " + rootPath);
91 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Common.dll")); 91 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Common.dll"));
92 parameters.ReferencedAssemblies.Add(Path.Combine(rootPathSE, "OpenSim.Region.ScriptEngine.DotNetEngine.dll")); 92 parameters.ReferencedAssemblies.Add(Path.Combine(rootPathSE, "OpenSim.Region.ScriptEngine.DotNetEngine.dll"));
93 93
94 //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment"); 94 //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment");
95 parameters.GenerateExecutable = false; 95 parameters.GenerateExecutable = false;
96 parameters.OutputAssembly = OutFile; 96 parameters.OutputAssembly = OutFile;
97 parameters.IncludeDebugInformation = false; 97 parameters.IncludeDebugInformation = false;
98 CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Script); 98 CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Script);
99 99
100 // Go through errors 100 // Go through errors
101 // TODO: Return errors to user somehow 101 // TODO: Return errors to user somehow
102 if (results.Errors.Count > 0) 102 if (results.Errors.Count > 0)
103 { 103 {
104 104
105 string errtext = ""; 105 string errtext = "";
106 foreach (CompilerError CompErr in results.Errors) 106 foreach (CompilerError CompErr in results.Errors)
107 { 107 {
108 errtext += "Line number " + (CompErr.Line - 1) + 108 errtext += "Line number " + (CompErr.Line - 1) +
109 ", Error Number: " + CompErr.ErrorNumber + 109 ", Error Number: " + CompErr.ErrorNumber +
110 ", '" + CompErr.ErrorText + "'\r\n"; 110 ", '" + CompErr.ErrorText + "'\r\n";
111 } 111 }
112 throw new Exception(errtext); 112 throw new Exception(errtext);
113 } 113 }
114 114
115 115
116 return OutFile; 116 return OutFile;
117 } 117 }
118 118
119 } 119 }
120} 120}
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/c_sharp_example.txt b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/c_sharp_example.txt
new file mode 100644
index 0000000..a39d1db
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/c_sharp_example.txt
@@ -0,0 +1,12 @@
1//c#
2namespace SecondLife {
3 public class Script : OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass
4{
5 public Script() { }
6
7 public void default_event_state_entry( )
8 {
9 llSay(0, "testing, I've been touched");
10 }
11
12}} \ No newline at end of file