aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.Region/Scenes/scripting/CSharpScriptEngine.cs
diff options
context:
space:
mode:
authorAdam Frisby2007-06-28 08:09:05 +0000
committerAdam Frisby2007-06-28 08:09:05 +0000
commit0c1a6c85cc678effc882dd5897d3357416807ba9 (patch)
tree6149f74c6a5a4d75bbeea3711a687dc6dcc66a6f /OpenSim/OpenSim.Region/Scenes/scripting/CSharpScriptEngine.cs
parentSome very Preliminary work on .net remoting for interregion comms. (diff)
downloadopensim-SC-0c1a6c85cc678effc882dd5897d3357416807ba9.zip
opensim-SC-0c1a6c85cc678effc882dd5897d3357416807ba9.tar.gz
opensim-SC-0c1a6c85cc678effc882dd5897d3357416807ba9.tar.bz2
opensim-SC-0c1a6c85cc678effc882dd5897d3357416807ba9.tar.xz
* Brand spankin' new scripting engine.
* Use "script load somefile.cs" for C# scripting. Will commit additional languages shortly. Scripts should implement the IScript interfaces to work correctly. * Someone port this over to NameSpaceChanges (built in Sugilite since sugilite is working)
Diffstat (limited to '')
-rw-r--r--OpenSim/OpenSim.Region/Scenes/scripting/CSharpScriptEngine.cs77
1 files changed, 77 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.Region/Scenes/scripting/CSharpScriptEngine.cs b/OpenSim/OpenSim.Region/Scenes/scripting/CSharpScriptEngine.cs
new file mode 100644
index 0000000..d5622b8
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scenes/scripting/CSharpScriptEngine.cs
@@ -0,0 +1,77 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5// Compilation stuff
6using System.CodeDom;
7using System.CodeDom.Compiler;
8using Microsoft.CSharp;
9
10namespace OpenSim.Scripting
11{
12 public class CSharpScriptEngine : IScriptCompiler
13 {
14 public string fileExt()
15 {
16 return ".cs";
17 }
18
19 private Dictionary<string,IScript> LoadDotNetScript(ICodeCompiler compiler, string filename)
20 {
21 CompilerParameters compilerParams = new CompilerParameters();
22 CompilerResults compilerResults;
23 compilerParams.GenerateExecutable = false;
24 compilerParams.GenerateInMemory = true;
25 compilerParams.IncludeDebugInformation = false;
26 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
27 compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
28 compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
29 compilerParams.ReferencedAssemblies.Add("System.dll");
30
31 compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
32
33 if (compilerResults.Errors.Count > 0)
34 {
35 OpenSim.Framework.Console.MainLog.Instance.Error("Compile errors");
36 foreach (CompilerError error in compilerResults.Errors)
37 {
38 OpenSim.Framework.Console.MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
39 }
40 }
41 else
42 {
43 Dictionary<string,IScript> scripts = new Dictionary<string,IScript>();
44
45 foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
46 {
47 Type testInterface = pluginType.GetInterface("IScript", true);
48
49 if (testInterface != null)
50 {
51 IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
52
53 string scriptName = "C#/" + script.getName();
54 Console.WriteLine("Script: " + scriptName + " loaded.");
55
56 if (!scripts.ContainsKey(scriptName))
57 {
58 scripts.Add(scriptName, script);
59 }
60 else
61 {
62 scripts[scriptName] = script;
63 }
64 }
65 }
66 return scripts;
67 }
68 return null;
69 }
70
71 public Dictionary<string,IScript> compile(string filename)
72 {
73 CSharpCodeProvider csharpProvider = new CSharpCodeProvider();
74 return LoadDotNetScript(csharpProvider.CreateCompiler(), filename);
75 }
76 }
77}