From ebb0099816299108b025b55e62ef1f15fe60c2f9 Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Sun, 26 Aug 2007 13:31:58 +0000 Subject: Run-time script errors are now shown in-world. No line number though, might require script to be compiled with (slow) debug information. --- .../DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | 26 ++++++++- .../ScriptEngine/DotNetEngine/EventQueueManager.cs | 29 ++++++++++ .../ScriptEngine/DotNetEngine/ScriptManager.cs | 67 +++++++++++++--------- 3 files changed, 93 insertions(+), 29 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine') diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs index bbb9f06..bac8bde 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs @@ -13,15 +13,17 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL public LSL2CSConverter() { + DataTypes.Add("void", "void"); - DataTypes.Add("integer", "int"); - DataTypes.Add("float", "double"); + DataTypes.Add("integer", "System.Int32"); + DataTypes.Add("float", "System.Double"); DataTypes.Add("string", "string"); - DataTypes.Add("key", "string"); + DataTypes.Add("key", "System.String"); DataTypes.Add("vector", "LSL_Types.Vector3"); DataTypes.Add("rotation", "LSL_Types.Quaternion"); DataTypes.Add("list", "list"); DataTypes.Add("null", "null"); + } @@ -227,11 +229,29 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL // Add namespace, class name and inheritance + Return = "" + "using System; " + "using System.Collections.Generic; " + "using System.Text; " + "using OpenSim.Region.ScriptEngine.Common; " + + "using integer = System.Int32; " + + "using key = System.String; "; + + //// Make a Using out of DataTypes + //// Using integer = System.Int32; + //string _val; + //foreach (string key in DataTypes.Keys) + //{ + // DataTypes.TryGetValue(key, out _val); + // if (key != _val) + // { + // Return += "using " + key + " = " + _val + "; "; + // } + //} + + + Return += "" + "namespace SecondLife { "; Return += "" + //"[Serializable] " + diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs index 7018dfe..c724f01 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs @@ -177,6 +177,35 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine { myScriptEngine.myScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, QIS.FunctionName, QIS.param); } + catch (Exception e) + { + // DISPLAY ERROR INWORLD + string text = "Error executing script:\r\n"; + if (e.InnerException != null) + { // Send inner exception + text += e.InnerException.Message.ToString(); + } + else + { // Send normal + text += e.Message.ToString(); + } + try + { + if (text.Length > 1500) + text = text.Substring(0, 1500); + IScriptHost m_host = myScriptEngine.World.GetSceneObjectPart(QIS.localID); + //if (m_host != null) + //{ + myScriptEngine.World.SimChat(Helpers.StringToField(text), 1, m_host.AbsolutePosition, m_host.Name, m_host.UUID); + } catch { + //} + //else + //{ + // T oconsole + Console.WriteLine("Unable to send text in-world:\r\n" + text); + } + + } finally { ReleaseLock(QIS.localID); diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs index 5dc928a..1944025 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs @@ -39,6 +39,7 @@ using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL; using OpenSim.Region.ScriptEngine.Common; using libsecondlife; + namespace OpenSim.Region.ScriptEngine.DotNetEngine { /// @@ -49,7 +50,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine [Serializable] public class ScriptManager { - + #region Declares private Thread ScriptLoadUnloadThread; private int ScriptLoadUnloadThread_IdleSleepms = 100; private Queue LoadQueue = new Queue(); @@ -66,6 +67,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine public LLUUID itemID; } + // Object> + // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. + // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead! + internal Dictionary> Scripts = new Dictionary>(); + public Scene World + { + get + { + return m_scriptEngine.World; + } + } +#endregion + #region Object init/shutdown private ScriptEngine m_scriptEngine; public ScriptManager(ScriptEngine scriptEngine) { @@ -96,6 +110,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine { } } + #endregion + #region Load / Unload scripts (Thread loop) private void ScriptLoadUnloadThreadLoop() { try @@ -129,7 +145,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine } } - + #endregion + #region Helper functions private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { @@ -139,19 +156,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine } - // Object> - // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. - // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead! - internal Dictionary> Scripts = new Dictionary>(); - public Scene World - { - get - { - return m_scriptEngine.World; - } - } - - + #endregion + #region Internal functions to keep track of script internal Dictionary.KeyCollection GetScriptKeys(uint localID) { if (Scripts.ContainsKey(localID) == false) @@ -212,6 +218,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine Obj.Remove(itemID); } + #endregion + #region Start/Stop script /// /// Fetches, loads and hooks up a script to an objects events /// @@ -346,9 +354,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine //return TempDotNetMicroThreadingCodeInjector.TestFix(FileName); return FileName; } - - - + #endregion + #region Perform event execution in script /// /// Execute a LL-event-function in Script /// @@ -366,16 +373,24 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine return; // Must be done in correct AppDomain, so leaving it up to the script itself - try - { - Script.Exec.ExecuteEvent(FunctionName, args); - } - catch (Exception e) - { - Console.WriteLine("Exception executing script funcion: " + e.ToString()); - } + Script.Exec.ExecuteEvent(FunctionName, args); + + } + #endregion + + #region Script serialization/deserialization + public void GetSerializedScript(uint localID, LLUUID itemID) + { + // Serialize the script and return it + // Should not be a problem } + public void PutSerializedScript(uint localID, LLUUID itemID) + { + // Deserialize the script and inject it into an AppDomain + // How to inject into an AppDomain? + } + #endregion } } -- cgit v1.1