diff options
author | Tedd Hansen | 2007-08-14 19:06:57 +0000 |
---|---|---|
committer | Tedd Hansen | 2007-08-14 19:06:57 +0000 |
commit | 16defc30eb2a01ce80b59511120066531363cc83 (patch) | |
tree | 7264fe86b5ee4ab569ec1afb7cc3ddda3f33b2b1 /OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs | |
parent | Can now create some new empty inventory items (like notecards and scripts) fr... (diff) | |
download | opensim-SC_OLD-16defc30eb2a01ce80b59511120066531363cc83.zip opensim-SC_OLD-16defc30eb2a01ce80b59511120066531363cc83.tar.gz opensim-SC_OLD-16defc30eb2a01ce80b59511120066531363cc83.tar.bz2 opensim-SC_OLD-16defc30eb2a01ce80b59511120066531363cc83.tar.xz |
krinkec's updates to ll* interface and functions
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs | 112 |
1 files changed, 67 insertions, 45 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs index 5f50a52..2de4e62 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs | |||
@@ -34,6 +34,11 @@ using System.Reflection; | |||
34 | 34 | ||
35 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | 35 | namespace OpenSim.Region.ScriptEngine.DotNetEngine |
36 | { | 36 | { |
37 | /// <summary> | ||
38 | /// Loads scripts | ||
39 | /// Compiles them if necessary | ||
40 | /// Execute functions for EventQueueManager | ||
41 | /// </summary> | ||
37 | class ScriptManager | 42 | class ScriptManager |
38 | { | 43 | { |
39 | 44 | ||
@@ -106,51 +111,63 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
106 | 111 | ||
107 | // We will initialize and start the script. | 112 | // We will initialize and start the script. |
108 | // It will be up to the script itself to hook up the correct events. | 113 | // It will be up to the script itself to hook up the correct events. |
109 | string FileName; | 114 | string FileName = ""; |
110 | 115 | ||
111 | // * Fetch script from server | 116 | try |
112 | // DEBUG - ScriptID is an actual filename during debug | ||
113 | // (therefore we can also check type by looking at extension) | ||
114 | FileName = ScriptID; | ||
115 | |||
116 | // * Does script need compile? Send it to LSL compiler first. (TODO: Use (and clean) compiler cache) | ||
117 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager Script extension: " + System.IO.Path.GetExtension(FileName).ToLower()); | ||
118 | switch (System.IO.Path.GetExtension(FileName).ToLower()) | ||
119 | { | 117 | { |
120 | case ".txt": | ||
121 | case ".lsl": | ||
122 | case ".cs": | ||
123 | myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager Script is CS/LSL, compiling to .Net Assembly"); | ||
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."); | ||
131 | } | ||
132 | |||
133 | myScriptEngine.m_logger.Verbose("ScriptEngine", "Compilation done"); | ||
134 | // * Insert yield into code | ||
135 | FileName = ProcessYield(FileName); | ||
136 | 118 | ||
137 | // * Find next available AppDomain to put it in | ||
138 | AppDomain FreeAppDomain = GetFreeAppDomain(); | ||
139 | 119 | ||
140 | // * Load and start script | 120 | // * Fetch script from server |
141 | //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName); | 121 | // DEBUG - ScriptID is an actual filename during debug |
142 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName); | 122 | // (therefore we can also check type by looking at extension) |
143 | string FullScriptID = ScriptID + "." + ObjectID; | 123 | FileName = ScriptID; |
144 | // Add it to our temporary active script keeper | 124 | |
145 | //Scripts.Add(FullScriptID, Script); | 125 | // * Does script need compile? Send it to LSL compiler first. (TODO: Use (and clean) compiler cache) |
146 | SetScript(ObjectID, ScriptID, Script); | 126 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager Script extension: " + System.IO.Path.GetExtension(FileName).ToLower()); |
147 | // We need to give (untrusted) assembly a private instance of BuiltIns | 127 | switch (System.IO.Path.GetExtension(FileName).ToLower()) |
148 | // this private copy will contain Read-Only FullScriptID so that it can bring that on to the server whenever needed. | 128 | { |
149 | //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands_Interface LSLB = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands_TestImplementation(FullScriptID); | 129 | case ".txt": |
130 | case ".lsl": | ||
131 | case ".cs": | ||
132 | myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager Script is CS/LSL, compiling to .Net Assembly"); | ||
133 | // Create a new instance of the compiler (currently we don't want reuse) | ||
134 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler LSLCompiler = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler(); | ||
135 | // Compile | ||
136 | FileName = LSLCompiler.Compile(FileName); | ||
137 | break; | ||
138 | default: | ||
139 | throw new Exception("Unknown script type."); | ||
140 | } | ||
141 | |||
142 | |||
143 | |||
144 | myScriptEngine.m_logger.Verbose("ScriptEngine", "Compilation done"); | ||
145 | // * Insert yield into code | ||
146 | FileName = ProcessYield(FileName); | ||
147 | |||
148 | // * Find next available AppDomain to put it in | ||
149 | AppDomain FreeAppDomain = GetFreeAppDomain(); | ||
150 | |||
151 | // * Load and start script | ||
152 | //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName); | ||
153 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName); | ||
154 | string FullScriptID = ScriptID + "." + ObjectID; | ||
155 | // Add it to our temporary active script keeper | ||
156 | //Scripts.Add(FullScriptID, Script); | ||
157 | SetScript(ObjectID, ScriptID, Script); | ||
158 | // We need to give (untrusted) assembly a private instance of BuiltIns | ||
159 | // this private copy will contain Read-Only FullScriptID so that it can bring that on to the server whenever needed. | ||
160 | //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands_Interface LSLB = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands_TestImplementation(FullScriptID); | ||
161 | |||
162 | // Start the script - giving it BuiltIns | ||
163 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager initializing script, handing over private builtin command interface"); | ||
164 | Script.Start(myScriptEngine.World, ScriptID); | ||
150 | 165 | ||
151 | // Start the script - giving it BuiltIns | 166 | } |
152 | //myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager initializing script, handing over private builtin command interface"); | 167 | catch (Exception e) |
153 | Script.Start(myScriptEngine.World, ScriptID); | 168 | { |
169 | myScriptEngine.m_logger.Error("ScriptEngine", "Exception loading script \"" + FileName + "\": " + e.ToString()); | ||
170 | } | ||
154 | 171 | ||
155 | 172 | ||
156 | } | 173 | } |
@@ -222,13 +239,18 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
222 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = myScriptEngine.myScriptManager.GetScript(ObjectID, ScriptID); | 239 | OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = myScriptEngine.myScriptManager.GetScript(ObjectID, ScriptID); |
223 | 240 | ||
224 | Type type = Script.GetType(); | 241 | Type type = Script.GetType(); |
225 | //object o = (object)Script; | ||
226 | 242 | ||
227 | //System.Collections.Generic.List<string> Functions = (System.Collections.Generic.List<string>) | 243 | |
228 | //Type type = typeof(OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass); | ||
229 | myScriptEngine.m_logger.Verbose("ScriptEngine", "Invoke: \"" + Script.State + "_event_" + FunctionName + "\""); | 244 | myScriptEngine.m_logger.Verbose("ScriptEngine", "Invoke: \"" + Script.State + "_event_" + FunctionName + "\""); |
230 | type.InvokeMember(Script.State + "_event_" + FunctionName, BindingFlags.InvokeMethod, null, Script, args); | 245 | |
231 | //System.Collections.Generic.List<string> Functions = (System.Collections.Generic.List<string>)type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, Script, null); | 246 | try |
247 | { | ||
248 | type.InvokeMember(Script.State + "_event_" + FunctionName, BindingFlags.InvokeMethod, null, Script, args); | ||
249 | } | ||
250 | catch (Exception e) | ||
251 | { | ||
252 | myScriptEngine.m_logger.Error("ScriptEngine", "Exception attempting to executing script function: " + e.ToString()); | ||
253 | } | ||
232 | 254 | ||
233 | 255 | ||
234 | //foreach (MemberInfo mi in type.GetMembers()) | 256 | //foreach (MemberInfo mi in type.GetMembers()) |