aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
authorTedd Hansen2007-08-12 19:04:07 +0000
committerTedd Hansen2007-08-12 19:04:07 +0000
commited1208d04378b2ef9928ed270c99f4f99f3a30d5 (patch)
treeb801ad73f59f7c055fde2f3b75022735b1a8051d /OpenSim/Region/ScriptEngine
parentScriptManager now uses LSL-compiler. (diff)
downloadopensim-SC_OLD-ed1208d04378b2ef9928ed270c99f4f99f3a30d5.zip
opensim-SC_OLD-ed1208d04378b2ef9928ed270c99f4f99f3a30d5.tar.gz
opensim-SC_OLD-ed1208d04378b2ef9928ed270c99f4f99f3a30d5.tar.bz2
opensim-SC_OLD-ed1208d04378b2ef9928ed270c99f4f99f3a30d5.tar.xz
ScriptEngine successfully compiles script, we are now even further than LSO was.
Also added C# script support.
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs19
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs22
3 files changed, 35 insertions, 10 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
index 906b2d3..2c514fc 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs
@@ -20,8 +20,25 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
20 // Output assembly name 20 // Output assembly name
21 string OutFile = Path.GetFileNameWithoutExtension(LSOFileName) + ".dll"; 21 string OutFile = Path.GetFileNameWithoutExtension(LSOFileName) + ".dll";
22 22
23 Common.SendToDebug("Reading source code into memory");
23 // TODO: Add error handling 24 // TODO: Add error handling
24 string CS_Code = LSL_Converter.Convert(File.ReadAllText(LSOFileName)); 25 string CS_Code;
26 switch (System.IO.Path.GetExtension(LSOFileName).ToLower())
27 {
28 case ".txt":
29 case ".lsl":
30 Common.SendToDebug("Source code is LSL, converting to CS");
31 CS_Code = LSL_Converter.Convert(File.ReadAllText(LSOFileName));
32 break;
33 case ".cs":
34 Common.SendToDebug("Source code is CS");
35 CS_Code = File.ReadAllText(LSOFileName);
36 break;
37 default:
38 throw new Exception("Unknown script type.");
39 }
40
41 Common.SendToDebug("Compiling");
25 42
26 // Do actual compile 43 // Do actual compile
27 System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters(); 44 System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
index 99fdb0d..6b0afa9 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
@@ -162,7 +162,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
162 // void dataserver(key query_id, string data) { 162 // void dataserver(key query_id, string data) {
163 //cache = Regex.Replace(cache, @"([^a-zA-Z_]\s*)((?!if|switch|for)[a-zA-Z_]+\s*\([^\)]*\)[^{]*{)", "$1" + "<STATE>" + "$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 163 //cache = Regex.Replace(cache, @"([^a-zA-Z_]\s*)((?!if|switch|for)[a-zA-Z_]+\s*\([^\)]*\)[^{]*{)", "$1" + "<STATE>" + "$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
164 //Console.WriteLine("Replacing using statename: " + current_statename); 164 //Console.WriteLine("Replacing using statename: " + current_statename);
165 cache = Regex.Replace(cache, @"^(\s*)((?!if|switch|for)[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1" + current_statename + "_$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 165 cache = Regex.Replace(cache, @"^(\s*)((?!(if|switch|for)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1" + current_statename + "_$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
166 } 166 }
167 167
168 ret += cache; 168 ret += cache;
@@ -195,7 +195,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
195 } 195 }
196 196
197 // Add "void" in front of functions that needs it 197 // Add "void" in front of functions that needs it
198 Script = Regex.Replace(Script, @"^(\s*)((?!if|switch|for)[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1void $2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 198 Script = Regex.Replace(Script, @"^(\s*)((?!(if|switch|for)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1void $2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
199 199
200 // Replace <x,y,z> and <x,y,z,r> 200 // Replace <x,y,z> and <x,y,z,r>
201 Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*,[^,>]*)>", @"new Axiom.Math.Quaternion($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 201 Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*,[^,>]*)>", @"new Axiom.Math.Quaternion($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
index 832807d..c34889a 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
@@ -114,15 +114,23 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
114 FileName = ScriptID; 114 FileName = ScriptID;
115 115
116 // * Does script need compile? Send it to LSL compiler first. (TODO: Use (and clean) compiler cache) 116 // * Does script need compile? Send it to LSL compiler first. (TODO: Use (and clean) compiler cache)
117 if (FileName.ToLower().EndsWith(".lsl")) 117 Common.SendToDebug("ScriptManager Script extension: " + System.IO.Path.GetExtension(FileName).ToLower());
118 switch (System.IO.Path.GetExtension(FileName).ToLower())
118 { 119 {
119 Common.SendToDebug("ScriptManager Script is LSL, compiling to .Net Assembly"); 120 case ".txt":
120 // Create a new instance of the compiler (currently we don't want reuse) 121 case ".lsl":
121 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler LSLCompiler = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler(); 122 case ".cs":
122 // Compile 123 Common.SendToDebug("ScriptManager Script is CS/LSL, compiling to .Net Assembly");
123 FileName = LSLCompiler.Compile(FileName); 124 // Create a new instance of the compiler (currently we don't want reuse)
125 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler LSLCompiler = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler();
126 // Compile
127 FileName = LSLCompiler.Compile(FileName);
128 break;
129 default:
130 throw new Exception("Unknown script type.");
124 } 131 }
125 132
133 Common.SendToDebug("Compilation done");
126 // * Insert yield into code 134 // * Insert yield into code
127 FileName = ProcessYield(FileName); 135 FileName = ProcessYield(FileName);
128 136
@@ -197,7 +205,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
197 Type t; 205 Type t;
198 //try 206 //try
199 //{ 207 //{
200 t = a.GetType("LSL_ScriptObject", true); 208 t = a.GetType("SecondLife.Script", true);
201 //} 209 //}
202 //catch (Exception e) 210 //catch (Exception e)
203 //{ 211 //{