Run-time script errors are now shown in-world. No line number though, might require script to be compiled with (slow) debug information.

afrisby
Tedd Hansen 2007-08-26 13:31:58 +00:00
parent fda97aa3c5
commit ebb0099816
4 changed files with 108 additions and 42 deletions

View File

@ -45,8 +45,8 @@ namespace OpenSim.Region.ScriptEngine.Common
{
// IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
// Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead!
try
{
//try
//{
if (m_Running == false)
{
// Script is inactive, do not execute!
@ -68,7 +68,7 @@ namespace OpenSim.Region.ScriptEngine.Common
MethodInfo mi = type.GetMethod(EventName);
Events.Add(EventName, mi);
}
catch (Exception e)
catch
{
// Event name not found, cache it as not found
Events.Add(EventName, null);
@ -86,19 +86,21 @@ namespace OpenSim.Region.ScriptEngine.Common
}
// Found
try
{
//try
//{
// Invoke it
ev.Invoke(m_Script, args);
}
catch (Exception e)
{
// TODO: Send to correct place
Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString());
}
}
catch { }
//}
//catch (Exception e)
//{
// // TODO: Send to correct place
// Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString());
//}
//}
//catch { }
}

View File

@ -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] " +

View File

@ -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);

View File

@ -39,6 +39,7 @@ using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL;
using OpenSim.Region.ScriptEngine.Common;
using libsecondlife;
namespace OpenSim.Region.ScriptEngine.DotNetEngine
{
/// <summary>
@ -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<LoadStruct> LoadQueue = new Queue<LoadStruct>();
@ -66,6 +67,19 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
public LLUUID itemID;
}
// Object<string, Script<string, script>>
// IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
// Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead!
internal Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>> Scripts = new Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>>();
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<string, Script<string, script>>
// IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
// Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead!
internal Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>> Scripts = new Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>>();
public Scene World
{
get
{
return m_scriptEngine.World;
}
}
#endregion
#region Internal functions to keep track of script
internal Dictionary<LLUUID, LSL_BaseClass>.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
/// <summary>
/// Fetches, loads and hooks up a script to an objects events
/// </summary>
@ -346,9 +354,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
//return TempDotNetMicroThreadingCodeInjector.TestFix(FileName);
return FileName;
}
#endregion
#region Perform event execution in script
/// <summary>
/// Execute a LL-event-function in Script
/// </summary>
@ -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
}
}