diff options
author | Tedd Hansen | 2007-08-22 18:09:38 +0000 |
---|---|---|
committer | Tedd Hansen | 2007-08-22 18:09:38 +0000 |
commit | 5a86fd2c31ce0ede9825657c969ccaa1ef423d5c (patch) | |
tree | 66e62accbaf1b20242b82920537d40d156f0bf00 /OpenSim/Region/ScriptEngine/DotNetEngine/Compiler | |
parent | Added Scene.GetSceneObjectPart(uint localID) (diff) | |
download | opensim-SC_OLD-5a86fd2c31ce0ede9825657c969ccaa1ef423d5c.zip opensim-SC_OLD-5a86fd2c31ce0ede9825657c969ccaa1ef423d5c.tar.gz opensim-SC_OLD-5a86fd2c31ce0ede9825657c969ccaa1ef423d5c.tar.bz2 opensim-SC_OLD-5a86fd2c31ce0ede9825657c969ccaa1ef423d5c.tar.xz |
(Untested) Scripts are individually loaded into objects (on rez), and event fired likewise. Bugfixes coming in next commit.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler')
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs index ad2717c..9dd274e 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs | |||
@@ -13,39 +13,51 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
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 int ScriptCompileCounter = 0; | ||
16 | //private ICodeCompiler icc = codeProvider.CreateCompiler(); | 17 | //private ICodeCompiler icc = codeProvider.CreateCompiler(); |
17 | public string Compile(string LSOFileName) | 18 | public string CompileFromFile(string LSOFileName) |
18 | { | 19 | { |
19 | |||
20 | |||
21 | // Output assembly name | ||
22 | string OutFile = Path.Combine("ScriptEngines", Path.GetFileNameWithoutExtension(LSOFileName) + ".dll"); | ||
23 | //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll"); | ||
24 | |||
25 | Common.SendToDebug("Reading source code into memory"); | ||
26 | // TODO: Add error handling | ||
27 | string CS_Code; | 20 | string CS_Code; |
28 | switch (System.IO.Path.GetExtension(LSOFileName).ToLower()) | 21 | switch (System.IO.Path.GetExtension(LSOFileName).ToLower()) |
29 | { | 22 | { |
30 | case ".txt": | 23 | case ".txt": |
31 | case ".lsl": | 24 | case ".lsl": |
32 | Common.SendToDebug("Source code is LSL, converting to CS"); | 25 | Common.SendToDebug("Source code is LSL, converting to CS"); |
33 | CS_Code = LSL_Converter.Convert(File.ReadAllText(LSOFileName)); | 26 | return CompileFromLSLText(File.ReadAllText(LSOFileName)); |
34 | break; | ||
35 | case ".cs": | 27 | case ".cs": |
36 | Common.SendToDebug("Source code is CS"); | 28 | Common.SendToDebug("Source code is CS"); |
37 | CS_Code = File.ReadAllText(LSOFileName); | 29 | return CompileFromCSText(File.ReadAllText(LSOFileName)); |
38 | break; | ||
39 | default: | 30 | default: |
40 | throw new Exception("Unknown script type."); | 31 | throw new Exception("Unknown script type."); |
41 | } | 32 | } |
33 | } | ||
34 | /// <summary> | ||
35 | /// Converts script from LSL to CS and calls CompileFromCSText | ||
36 | /// </summary> | ||
37 | /// <param name="Script">LSL script</param> | ||
38 | /// <returns>Filename to .dll assembly</returns> | ||
39 | public string CompileFromLSLText(string Script) | ||
40 | { | ||
41 | return CompileFromCSText(LSL_Converter.Convert(Script)); | ||
42 | } | ||
43 | /// <summary> | ||
44 | /// Compile CS script to .Net assembly (.dll) | ||
45 | /// </summary> | ||
46 | /// <param name="Script">CS script</param> | ||
47 | /// <returns>Filename to .dll assembly</returns> | ||
48 | public string CompileFromCSText(string Script) | ||
49 | { | ||
42 | 50 | ||
43 | Common.SendToDebug("Compiling"); | 51 | |
52 | // Output assembly name | ||
53 | ScriptCompileCounter++; | ||
54 | string OutFile = Path.Combine("ScriptEngines", "Script_" + ScriptCompileCounter + ".dll"); | ||
55 | //string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll"); | ||
44 | 56 | ||
45 | // DEBUG - write source to disk | 57 | // DEBUG - write source to disk |
46 | try | 58 | try |
47 | { | 59 | { |
48 | File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(LSOFileName) + ".cs"), CS_Code); | 60 | File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script); |
49 | } | 61 | } |
50 | catch { } | 62 | catch { } |
51 | 63 | ||
@@ -68,7 +80,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
68 | //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment"); | 80 | //parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment"); |
69 | parameters.GenerateExecutable = false; | 81 | parameters.GenerateExecutable = false; |
70 | parameters.OutputAssembly = OutFile; | 82 | parameters.OutputAssembly = OutFile; |
71 | CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, CS_Code); | 83 | CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Script); |
72 | 84 | ||
73 | // Go through errors | 85 | // Go through errors |
74 | // TODO: Return errors to user somehow | 86 | // TODO: Return errors to user somehow |