Patch from Melanie: 0001077: [PATCH] LSL types cannot be cast implicitly or explicitly in many cases Thanks Melanie!

* Also, I moved the event parser and re-writer to a separate static object.   More work will be done here shortly.
0.6.0-stable
Teravus Ovares 2008-04-30 03:36:13 +00:00
parent 0880abc402
commit 36bf16d35e
11 changed files with 684 additions and 339 deletions

View File

@ -80,6 +80,15 @@ namespace OpenSim.Region.ScriptEngine.Common
// Set it if it changed // Set it if it changed
if (m_state != value) if (m_state != value)
{ {
try
{
m_ScriptEngine.m_EventManager.state_exit(m_localID);
}
catch (AppDomainUnloadedException)
{
Console.WriteLine("[SCRIPT]: state change called when script was unloaded. Nothing to worry about, but noting the occurance");
}
m_state = value; m_state = value;
try try
{ {
@ -2136,7 +2145,7 @@ namespace OpenSim.Region.ScriptEngine.Common
m_host.TaskInventory[invItemID].PermsMask=0; m_host.TaskInventory[invItemID].PermsMask=0;
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {(int)0}); m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(0)});
return; return;
} }
@ -2158,7 +2167,7 @@ namespace OpenSim.Region.ScriptEngine.Common
m_host.TaskInventory[invItemID].PermsMask=perm; m_host.TaskInventory[invItemID].PermsMask=perm;
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {(int)perm}); m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(perm)});
return; return;
} }
@ -2175,7 +2184,7 @@ namespace OpenSim.Region.ScriptEngine.Common
m_host.TaskInventory[invItemID].PermsMask=perm; m_host.TaskInventory[invItemID].PermsMask=perm;
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {(int)perm}); m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(perm)});
return; return;
} }
@ -2202,7 +2211,7 @@ namespace OpenSim.Region.ScriptEngine.Common
// Requested agent is not in range, refuse perms // Requested agent is not in range, refuse perms
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {(int)0}); m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(0)});
} }
void handleScriptAnswer(IClientAPI client, LLUUID taskID, LLUUID itemID, int answer) void handleScriptAnswer(IClientAPI client, LLUUID taskID, LLUUID itemID, int answer)
@ -2220,7 +2229,7 @@ namespace OpenSim.Region.ScriptEngine.Common
m_host.TaskInventory[invItemID].PermsMask=answer; m_host.TaskInventory[invItemID].PermsMask=answer;
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {(int)answer}); m_localID, m_itemID, "run_time_permissions", EventQueueManager.llDetectNull, new Object[] {new LSL_Types.LSLInteger(answer)});
} }
public string llGetPermissionsKey() public string llGetPermissionsKey()
@ -2600,7 +2609,7 @@ namespace OpenSim.Region.ScriptEngine.Common
object[] resobj = new object[] object[] resobj = new object[]
{ {
m_host.LinkNum + 1, num, msg, id new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
}; };
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
@ -2627,7 +2636,7 @@ namespace OpenSim.Region.ScriptEngine.Common
partItemID = item.ItemID; partItemID = item.ItemID;
Object[] resobj = new object[] Object[] resobj = new object[]
{ {
m_host.LinkNum + 1, num, msg, id new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
}; };
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
@ -2655,7 +2664,7 @@ namespace OpenSim.Region.ScriptEngine.Common
partItemID = item.ItemID; partItemID = item.ItemID;
Object[] resobj = new object[] Object[] resobj = new object[]
{ {
m_host.LinkNum + 1, num, msg, id new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
}; };
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
@ -2685,7 +2694,7 @@ namespace OpenSim.Region.ScriptEngine.Common
partItemID = item.ItemID; partItemID = item.ItemID;
Object[] resobj = new object[] Object[] resobj = new object[]
{ {
m_host.LinkNum + 1, num, msg, id new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
}; };
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
@ -2709,7 +2718,7 @@ namespace OpenSim.Region.ScriptEngine.Common
object[] resobj = new object[] object[] resobj = new object[]
{ {
m_host.LinkNum + 1, num, msg, id new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
}; };
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
@ -2737,7 +2746,7 @@ namespace OpenSim.Region.ScriptEngine.Common
partItemID = item.ItemID; partItemID = item.ItemID;
Object[] resObjDef = new object[] Object[] resObjDef = new object[]
{ {
m_host.LinkNum + 1, num, msg, id new LSL_Types.LSLInteger(m_host.LinkNum + 1), new LSL_Types.LSLInteger(num), new LSL_Types.LSLString(msg), new LSL_Types.LSLString(id)
}; };
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
@ -3058,7 +3067,14 @@ namespace OpenSim.Region.ScriptEngine.Common
{ {
return 0; return 0;
} }
return Convert.ToInt32(src.Data[index]); try
{
return Convert.ToInt32(src.Data[index]);
}
catch (System.FormatException e)
{
return 0;
}
} }
public double osList2Double(LSL_Types.list src, int index) public double osList2Double(LSL_Types.list src, int index)
@ -3086,7 +3102,14 @@ namespace OpenSim.Region.ScriptEngine.Common
{ {
return 0.0; return 0.0;
} }
return Convert.ToDouble(src.Data[index]); try
{
return Convert.ToDouble(src.Data[index]);
}
catch (System.FormatException e)
{
return 0.0;
}
} }
public string llList2String(LSL_Types.list src, int index) public string llList2String(LSL_Types.list src, int index)
@ -3112,18 +3135,9 @@ namespace OpenSim.Region.ScriptEngine.Common
} }
if (index >= src.Length) if (index >= src.Length)
{ {
return "00000000-0000-0000-0000-000000000000"; return "";
}
//return OpenSim.Framework.ToString(src[index]);
LLUUID tmpkey;
if (LLUUID.TryParse(src.Data[index].ToString(), out tmpkey))
{
return tmpkey.ToString();
}
else
{
return "00000000-0000-0000-0000-000000000000";
} }
return src.Data[index].ToString();
} }
public LSL_Types.Vector3 llList2Vector(LSL_Types.list src, int index) public LSL_Types.Vector3 llList2Vector(LSL_Types.list src, int index)
@ -4317,7 +4331,7 @@ namespace OpenSim.Region.ScriptEngine.Common
if (xmlrpcMod.IsEnabled()) if (xmlrpcMod.IsEnabled())
{ {
LLUUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID); LLUUID channelID = xmlrpcMod.OpenXMLRPCChannel(m_localID, m_itemID);
object[] resobj = new object[] { 1, channelID.ToString(), LLUUID.Zero.ToString(), String.Empty, 0, String.Empty }; object[] resobj = new object[] { new LSL_Types.LSLInteger(1), new LSL_Types.LSLString(channelID.ToString()), new LSL_Types.LSLString(LLUUID.Zero.ToString()), new LSL_Types.LSLString(String.Empty), new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(String.Empty) };
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(m_localID, m_itemID, "remote_data", EventQueueManager.llDetectNull, resobj); m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(m_localID, m_itemID, "remote_data", EventQueueManager.llDetectNull, resobj);
} }
} }

View File

@ -64,6 +64,11 @@ namespace OpenSim.Region.ScriptEngine.Common
str = str.Replace('<', ' '); str = str.Replace('<', ' ');
str = str.Replace('>', ' '); str = str.Replace('>', ' ');
string[] tmps = str.Split(new Char[] { ',', '<', '>' }); string[] tmps = str.Split(new Char[] { ',', '<', '>' });
if(tmps.Length < 3)
{
x=y=z=0;
return;
}
bool res; bool res;
res = Double.TryParse(tmps[0], out x); res = Double.TryParse(tmps[0], out x);
res = res & Double.TryParse(tmps[1], out y); res = res & Double.TryParse(tmps[1], out y);
@ -76,14 +81,27 @@ namespace OpenSim.Region.ScriptEngine.Common
public override string ToString() public override string ToString()
{ {
return "<" + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ">"; string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", x, y, z);
return s;
}
public static explicit operator LSLString(Vector3 vec)
{
string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z);
return new LSLString(s);
} }
public static explicit operator string(Vector3 vec) public static explicit operator string(Vector3 vec)
{ {
return "<" + vec.x.ToString() + ", " + vec.y.ToString() + ", " + vec.z.ToString() + ">"; string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z);
return s;
} }
public static explicit operator Vector3(string s)
{
return new Vector3(s);
}
public static bool operator ==(Vector3 lhs, Vector3 rhs) public static bool operator ==(Vector3 lhs, Vector3 rhs)
{ {
return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z); return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z);
@ -278,6 +296,11 @@ namespace OpenSim.Region.ScriptEngine.Common
str = str.Replace('<', ' '); str = str.Replace('<', ' ');
str = str.Replace('>', ' '); str = str.Replace('>', ' ');
string[] tmps = str.Split(new Char[] { ',', '<', '>' }); string[] tmps = str.Split(new Char[] { ',', '<', '>' });
if(tmps.Length < 4)
{
x=y=z=s=0;
return;
}
bool res; bool res;
res = Double.TryParse(tmps[0], out x); res = Double.TryParse(tmps[0], out x);
res = res & Double.TryParse(tmps[1], out y); res = res & Double.TryParse(tmps[1], out y);
@ -307,14 +330,27 @@ namespace OpenSim.Region.ScriptEngine.Common
public override string ToString() public override string ToString()
{ {
return "<" + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ", " + s.ToString() + ">"; string st=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", x, y, z, s);
return st;
} }
public static explicit operator string(Quaternion r) public static explicit operator string(Quaternion r)
{ {
return "<" + r.x.ToString() + ", " + r.y.ToString() + ", " + r.z.ToString() + ", " + r.s.ToString() + ">"; string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s);
return s;
} }
public static explicit operator LSLString(Quaternion r)
{
string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s);
return new LSLString(s);
}
public static explicit operator Quaternion(string s)
{
return new Quaternion(s);
}
public static bool operator ==(Quaternion lhs, Quaternion rhs) public static bool operator ==(Quaternion lhs, Quaternion rhs)
{ {
// Return true if the fields match: // Return true if the fields match:
@ -369,12 +405,20 @@ namespace OpenSim.Region.ScriptEngine.Common
public int Length public int Length
{ {
get { return m_data.Length; } get {
if(m_data == null)
m_data=new Object[0];
return m_data.Length;
}
} }
public object[] Data public object[] Data
{ {
get { return m_data; } get {
if(m_data == null)
m_data=new Object[0];
return m_data;
}
} }
public static list operator +(list a, list b) public static list operator +(list a, list b)
@ -571,13 +615,20 @@ namespace OpenSim.Region.ScriptEngine.Common
if(Data.Length == 0) if(Data.Length == 0)
return new list(); // Don't even bother return new list(); // Don't even bother
string[] keys;
if(stride == 1) // The simple case if(stride == 1) // The simple case
{ {
Object[] ret=new Object[Data.Length]; Object[] ret=new Object[Data.Length];
Array.Copy(Data, 0, ret, 0, Data.Length); Array.Copy(Data, 0, ret, 0, Data.Length);
Array.Sort(ret); keys=new string[Data.Length];
int k;
for(k=0;k<Data.Length;k++)
keys[k]=Data[k].ToString();
Array.Sort(keys, ret);
if(ascending == 0) if(ascending == 0)
Array.Reverse(ret); Array.Reverse(ret);
@ -588,7 +639,7 @@ namespace OpenSim.Region.ScriptEngine.Common
int len=(Data.Length+stride-1)/stride; int len=(Data.Length+stride-1)/stride;
string[] keys=new string[len]; keys=new string[len];
Object[][] vals=new Object[len][]; Object[][] vals=new Object[len][];
int i; int i;
@ -1016,17 +1067,7 @@ namespace OpenSim.Region.ScriptEngine.Common
public override bool Equals(object o) public override bool Equals(object o)
{ {
if (o is String) return o.ToString() == value;
{
string s = (string)o;
return s == this.value;
}
if (o is key)
{
key k = (key)o;
return this.value == k.value;
}
return false;
} }
public override int GetHashCode() public override int GetHashCode()
@ -1046,6 +1087,13 @@ namespace OpenSim.Region.ScriptEngine.Common
{ {
m_string = s; m_string = s;
} }
public LSLString(double d)
{
string s=String.Format("{0:0.000000}", d);
m_string=s;
}
#endregion #endregion
#region Operators #region Operators
@ -1071,44 +1119,47 @@ namespace OpenSim.Region.ScriptEngine.Common
return new LSLString(s); return new LSLString(s);
} }
// Commented out: public static string ToString(LSLString s)
/* {
[echo] Build Directory is /home/tedd/opensim/trunk/OpenSim/Region/ScriptEngine/Common/bin/Debug return s.m_string;
[csc] Compiling 5 files to '/home/tedd/opensim/trunk/OpenSim/Region/ScriptEngine/Common/bin/Debug/OpenSim.Region.ScriptEngine.Common.dll'. }
[csc] error CS0121: The call is ambiguous between the following methods or properties: `OpenSim.Region.ScriptEngine.Common.LSL_Types.LSLString.operator /(OpenSim.Region.ScriptEngine.Common.LSL_Types.LSLString, OpenSim.Region.ScriptEngine.Common.LSL_Types.LSLString)' and `string.operator /(string, string)'
[csc] /home/tedd/opensim/trunk/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs(602,32): (Location of the symbol related to previous error) public override string ToString()
[csc] /usr/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error) {
[csc] Compilation failed: 1 error(s), 0 warnings return m_string;
*/ }
//public static bool operator ==(LSLString s1, LSLString s2)
//{ public static bool operator ==(LSLString s1, string s2)
// return s1.m_string == s2.m_string; {
//} return s1.m_string == s2;
//public static bool operator !=(LSLString s1, LSLString s2) }
//{
// return s1.m_string != s2.m_string; public static bool operator !=(LSLString s1, string s2)
//} {
return s1.m_string != s2;
}
public static explicit operator double(LSLString s)
{
return Convert.ToDouble(s.m_string);
}
public static explicit operator LSLInteger(LSLString s)
{
return new LSLInteger(Convert.ToInt32(s.m_string));
}
public static explicit operator LSLString(double d)
{
return new LSLString(d);
}
#endregion #endregion
#region Overriders #region Overriders
public override bool Equals(object o) public override bool Equals(object o)
{ {
if (o is String) return m_string == o.ToString();
{
string s = (string)o;
return s == this.m_string;
}
if (o is key)
{
key k = (key)o;
return this.m_string == k.value;
}
if (o is LSLString)
{
LSLString s = (string)o;
return this.m_string == s;
}
return false;
} }
public override int GetHashCode() public override int GetHashCode()
@ -1154,6 +1205,11 @@ namespace OpenSim.Region.ScriptEngine.Common
return i.value; return i.value;
} }
static public explicit operator LSLString(LSLInteger i)
{
return new LSLString(i.ToString());
}
static public implicit operator Boolean(LSLInteger i) static public implicit operator Boolean(LSLInteger i)
{ {
if (i.value == 0) if (i.value == 0)
@ -1171,6 +1227,11 @@ namespace OpenSim.Region.ScriptEngine.Common
return new LSLInteger(i); return new LSLInteger(i);
} }
static public explicit operator LSLInteger(string s)
{
return new LSLInteger(int.Parse(s));
}
static public implicit operator LSLInteger(double d) static public implicit operator LSLInteger(double d)
{ {
return new LSLInteger(d); return new LSLInteger(d);
@ -1182,6 +1243,17 @@ namespace OpenSim.Region.ScriptEngine.Common
return ret; return ret;
} }
public static LSLInteger operator ++(LSLInteger i)
{
i.value++;
return i;
}
public static LSLInteger operator --(LSLInteger i)
{
i.value--;
return i;
}
//static public implicit operator System.Double(LSLInteger i) //static public implicit operator System.Double(LSLInteger i)
//{ //{

View File

@ -72,7 +72,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugin
{ {
object[] resobj = new object[] object[] resobj = new object[]
{ {
httpInfo.reqID.ToString(), httpInfo.status, null, httpInfo.response_body new LSL_Types.LSLString(httpInfo.reqID.ToString()), new LSL_Types.LSLInteger(httpInfo.status), null, new LSL_Types.LSLString(httpInfo.response_body)
}; };
sman.m_EventQueueManager.AddToScriptQueue( sman.m_EventQueueManager.AddToScriptQueue(

View File

@ -58,7 +58,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugin
object[] resobj = new object[] object[] resobj = new object[]
{ {
//lInfo.GetChannel(), lInfo.GetName(), lInfo.GetID().ToString(), lInfo.GetMessage() //lInfo.GetChannel(), lInfo.GetName(), lInfo.GetID().ToString(), lInfo.GetMessage()
lInfo.GetChannel(), lInfo.GetName(), lInfo.GetSourceItemID().ToString(), lInfo.GetMessage() new LSL_Types.LSLInteger(lInfo.GetChannel()), new LSL_Types.LSLString(lInfo.GetName()), new LSL_Types.LSLString(lInfo.GetSourceItemID().ToString()), new LSL_Types.LSLString(lInfo.GetMessage())
}; };
m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(

View File

@ -314,7 +314,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugin
else else
{ {
m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "sensor", EventQueueManager.llDetectNull, m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "sensor", EventQueueManager.llDetectNull,
new object[] { SensedObjects.Length }); new object[] { new LSL_Types.LSLInteger(SensedObjects.Length) });
} }
} }
} }

View File

@ -60,9 +60,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugin
//Deliver data to prim's remote_data handler //Deliver data to prim's remote_data handler
object[] resobj = new object[] object[] resobj = new object[]
{ {
2, rInfo.GetChannelKey().ToString(), rInfo.GetMessageID().ToString(), String.Empty, new LSL_Types.LSLInteger(2), new LSL_Types.LSLString(rInfo.GetChannelKey().ToString()), new LSL_Types.LSLString(rInfo.GetMessageID().ToString()), new LSL_Types.LSLString(String.Empty),
rInfo.GetIntValue(), new LSL_Types.LSLInteger(rInfo.GetIntValue()),
rInfo.GetStrVal() new LSL_Types.LSLString(rInfo.GetStrVal())
}; };
m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
rInfo.GetLocalID(), rInfo.GetItemID(), "remote_data", EventQueueManager.llDetectNull, resobj rInfo.GetLocalID(), rInfo.GetItemID(), "remote_data", EventQueueManager.llDetectNull, resobj
@ -83,9 +83,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugin
//Deliver data to prim's remote_data handler //Deliver data to prim's remote_data handler
object[] resobj = new object[] object[] resobj = new object[]
{ {
3, srdInfo.channel.ToString(), srdInfo.GetReqID().ToString(), String.Empty, new LSL_Types.LSLInteger(3), new LSL_Types.LSLString(srdInfo.channel.ToString()), new LSL_Types.LSLString(srdInfo.GetReqID().ToString()), new LSL_Types.LSLString(String.Empty),
srdInfo.idata, new LSL_Types.LSLInteger(srdInfo.idata),
srdInfo.sdata new LSL_Types.LSLString(srdInfo.sdata)
}; };
m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue( m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
srdInfo.m_localID, srdInfo.m_itemID, "remote_data", EventQueueManager.llDetectNull, resobj srdInfo.m_localID, srdInfo.m_itemID, "remote_data", EventQueueManager.llDetectNull, resobj

View File

@ -100,7 +100,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public void changed(uint localID, uint change) public void changed(uint localID, uint change)
{ {
// Add to queue for all scripts in localID, Object pass change. // Add to queue for all scripts in localID, Object pass change.
myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "changed", EventQueueManager.llDetectNull, new object[] { (int)change }); myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "changed", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(change) });
} }
public void state_entry(uint localID) public void state_entry(uint localID)
@ -115,7 +115,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
EventQueueManager.Queue_llDetectParams_Struct detstruct = new EventQueueManager.Queue_llDetectParams_Struct(); EventQueueManager.Queue_llDetectParams_Struct detstruct = new EventQueueManager.Queue_llDetectParams_Struct();
detstruct._key = new LSL_Types.key[1]; detstruct._key = new LSL_Types.key[1];
detstruct._key[0] = new LSL_Types.key(remoteClient.AgentId.ToString()); detstruct._key[0] = new LSL_Types.key(remoteClient.AgentId.ToString());
myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "touch_start", detstruct, new object[] { (int)1 }); myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "touch_start", detstruct, new object[] { new LSL_Types.LSLInteger(1) });
} }
public void touch_end(uint localID, IClientAPI remoteClient) public void touch_end(uint localID, IClientAPI remoteClient)
@ -124,7 +124,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
EventQueueManager.Queue_llDetectParams_Struct detstruct = new EventQueueManager.Queue_llDetectParams_Struct(); EventQueueManager.Queue_llDetectParams_Struct detstruct = new EventQueueManager.Queue_llDetectParams_Struct();
detstruct._key = new LSL_Types.key[1]; detstruct._key = new LSL_Types.key[1];
detstruct._key[0] = new LSL_Types.key(remoteClient.AgentId.ToString()); detstruct._key[0] = new LSL_Types.key(remoteClient.AgentId.ToString());
myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "touch_end", detstruct, new object[] { (int)1 }); myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "touch_end", detstruct, new object[] { new LSL_Types.LSLInteger(1) });
} }
public void OnRezScript(uint localID, LLUUID itemID, string script) public void OnRezScript(uint localID, LLUUID itemID, string script)
@ -145,7 +145,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public void money(uint localID, LLUUID agentID, int amount) public void money(uint localID, LLUUID agentID, int amount)
{ {
myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "money", EventQueueManager.llDetectNull, new object[] { agentID.ToString(), (int)amount }); myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "money", EventQueueManager.llDetectNull, new object[] { agentID.ToString(), new LSL_Types.LSLInteger(amount) });
} }
// TODO: Replace placeholders below // TODO: Replace placeholders below
@ -154,9 +154,10 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
// then queued in EventQueueManager. // then queued in EventQueueManager.
// When queued in EventQueueManager they need to be LSL compatible (name and params) // When queued in EventQueueManager they need to be LSL compatible (name and params)
public void state_exit(uint localID, LLUUID itemID) public void state_exit(uint localID)
{ {
myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_exit", EventQueueManager.llDetectNull); // Add to queue for all scripts in ObjectID object
myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "state_exit", EventQueueManager.llDetectNull, new object[] { });
} }
public void touch(uint localID, LLUUID itemID) public void touch(uint localID, LLUUID itemID)
@ -166,22 +167,22 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public void touch_end(uint localID, LLUUID itemID) public void touch_end(uint localID, LLUUID itemID)
{ {
myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "touch_end", EventQueueManager.llDetectNull); myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "touch_end", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(1) });
} }
public void collision_start(uint localID, LLUUID itemID) public void collision_start(uint localID, LLUUID itemID)
{ {
myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision_start", EventQueueManager.llDetectNull, new object[] { (int)1 }); myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision_start", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(1) });
} }
public void collision(uint localID, LLUUID itemID) public void collision(uint localID, LLUUID itemID)
{ {
myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision", EventQueueManager.llDetectNull, new object[] { (int)1 }); myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(1) });
} }
public void collision_end(uint localID, LLUUID itemID) public void collision_end(uint localID, LLUUID itemID)
{ {
myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision_end", EventQueueManager.llDetectNull, new object[] { (int)1 }); myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "collision_end", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(1) });
} }
public void land_collision_start(uint localID, LLUUID itemID) public void land_collision_start(uint localID, LLUUID itemID)
@ -237,7 +238,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
public void at_target(uint localID, uint handle, LLVector3 targetpos, LLVector3 atpos) public void at_target(uint localID, uint handle, LLVector3 targetpos, LLVector3 atpos)
{ {
myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "at_target", EventQueueManager.llDetectNull, new object[] { (int)handle, new LSL_Types.Vector3(targetpos.X,targetpos.Y,targetpos.Z), new LSL_Types.Vector3(atpos.X,atpos.Y,atpos.Z) }); myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "at_target", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(handle), new LSL_Types.Vector3(targetpos.X,targetpos.Y,targetpos.Z), new LSL_Types.Vector3(atpos.X,atpos.Y,atpos.Z) });
} }
public void not_at_target(uint localID) public void not_at_target(uint localID)

View File

@ -40,7 +40,7 @@ namespace OpenSim.Region.ScriptEngine.Common
void touch_start(uint localID, LLVector3 offsetPos, IClientAPI remoteClient); void touch_start(uint localID, LLVector3 offsetPos, IClientAPI remoteClient);
void OnRezScript(uint localID, LLUUID itemID, string script); void OnRezScript(uint localID, LLUUID itemID, string script);
void OnRemoveScript(uint localID, LLUUID itemID); void OnRemoveScript(uint localID, LLUUID itemID);
void state_exit(uint localID, LLUUID itemID); void state_exit(uint localID);
void touch(uint localID, LLUUID itemID); void touch(uint localID, LLUUID itemID);
void touch_end(uint localID, LLUUID itemID); void touch_end(uint localID, LLUUID itemID);
void collision_start(uint localID, LLUUID itemID); void collision_start(uint localID, LLUUID itemID);

View File

@ -319,6 +319,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
private static string CreateCSCompilerScript(string compileScript) private static string CreateCSCompilerScript(string compileScript)
{ {
compileScript = EventReaderRewriter.ReWriteScriptWithPublishedEventsCS(compileScript);
compileScript = String.Empty + compileScript = String.Empty +
"using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;\r\n" + "using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;\r\n" +
String.Empty + "namespace SecondLife { " + String.Empty + "namespace SecondLife { " +

View File

@ -0,0 +1,488 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
{
public static class EventReaderRewriter
{
public static string ReWriteScriptWithPublishedEventsCS(string Script)
{
Dictionary<string, scriptEvents> state_events = new Dictionary<string, scriptEvents>();
// Finds out which events are in the script and writes a method call with the events in each state_entry event
// Note the (?:)? block optional, and not returning a group. Less greedy then .*
string[] eventmatches = new string[0];
//Regex stateevents = new Regex(@"(public void )([^_]+)(_event_)([^\(]+)[\(\)]+\s+[^\{]\{");
eventmatches = Regex.Split(Script, @"public void\s([^_]+)_event_([^\(]+)\((?:[a-zA-Z0-9\s_,\.\-]+)?\)(?:[^\{]+)?\{", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
for (int pos = 0; pos < eventmatches.GetUpperBound(0); pos++)
{
pos++; // garbage
string statea = eventmatches[pos]; pos++;
string eventa = eventmatches[pos];
scriptEvents storedEventsForState = scriptEvents.None;
if (state_events.ContainsKey(statea))
{
storedEventsForState = state_events[statea];
state_events[statea] |= convertnametoFlag(eventa);
}
else
{
state_events.Add(statea, convertnametoFlag(eventa));
}
Console.WriteLine("State:" + statea + ", event: " + eventa);
}
Console.WriteLine("Matches:" + eventmatches.GetUpperBound(0));
// Add namespace, class name and inheritance
// Looking *ONLY* for state entry events
string scriptCopy = "";
//Only match State_Entry events now
// Note the whole regex is a group, then we have the state this entry belongs to.
eventmatches = Regex.Split(Script, @"(public void\s([^_]+)_event_state_entry[\(\)](?:[^\{]+)?\{)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
int endloop = eventmatches.GetUpperBound(0);
// Add all the states to a list of
List<string> unUsedStates = new List<string>();
foreach (string state in state_events.Keys)
{
unUsedStates.Add(state);
}
// If endloop is 0, then there are no state entry events in the entire script.
// Stick a default state entry in there.
if (endloop == 0)
{
if (state_events.ContainsKey("default"))
{
scriptCopy = "public void default_event_state_entry() {osSetStateEvents((int)" + (int)state_events["default"] + "); } " + Script;
unUsedStates.Remove("default");
}
else
{
throw new Exception("You must define a default state. Compile failed. See LSL documentation for more details.");
}
}
// Loop over state entry events and rewrite the first line to define the events the state listens for.
for (int pos = 0; pos < endloop; pos++)
{
// Returns text before state entry match,
scriptCopy += eventmatches[pos]; pos++;
// Returns text of state entry match,
scriptCopy += eventmatches[pos]; pos++;
// Returns which state we're matching and writes a method call to the end of the above state_entry
scriptCopy += "osSetStateEvents((int)" + (int)state_events[eventmatches[pos]] + ");"; //pos++;
// Remove the state from the unused list. There might be more states matched then defined, so we
// check if the state was defined first
if (unUsedStates.Contains(eventmatches[pos]))
unUsedStates.Remove(eventmatches[pos]);
// adds the remainder of the script.
if ((pos + 1) == endloop)
{
pos++;
scriptCopy += eventmatches[pos++];
}
}
// states with missing state_entry blocks won't publish their events,
// so, to fix that we write a state entry with only the event publishing method for states missing a state_entry event
foreach (string state in unUsedStates)
{
// Write the remainder states out into a blank state entry with the event setting routine
scriptCopy = "public void " + state + "_event_state_entry() {tosSetStateEvents((int)" + (int)state_events[state] + ");} " + scriptCopy;
}
// save modified script.
unUsedStates.Clear();
state_events.Clear();
return scriptCopy;
}
public static string ReWriteScriptWithPublishedEventsJS(string Script)
{
Dictionary<string, scriptEvents> state_events = new Dictionary<string, scriptEvents>();
// Finds out which events are in the script and writes a method call with the events in each state_entry event
// Note the (?:)? block optional, and not returning a group. Less greedy then .*
string[] eventmatches = new string[0];
//Regex stateevents = new Regex(@"(public void )([^_]+)(_event_)([^\(]+)[\(\)]+\s+[^\{]\{");
eventmatches = Regex.Split(Script, @"function \s([^_]+)_event_([^\(]+)\((?:[a-zA-Z0-9\s_,\.\-]+)?\)(?:[^\{]+)?\{", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
for (int pos = 0; pos < eventmatches.GetUpperBound(0); pos++)
{
pos++; // garbage
string statea = eventmatches[pos]; pos++;
string eventa = eventmatches[pos];
scriptEvents storedEventsForState = scriptEvents.None;
if (state_events.ContainsKey(statea))
{
storedEventsForState = state_events[statea];
state_events[statea] |= convertnametoFlag(eventa);
}
else
{
state_events.Add(statea, convertnametoFlag(eventa));
}
Console.WriteLine("State:" + statea + ", event: " + eventa);
}
Console.WriteLine("Matches:" + eventmatches.GetUpperBound(0));
// Add namespace, class name and inheritance
// Looking *ONLY* for state entry events
string scriptCopy = "";
//Only match State_Entry events now
// Note the whole regex is a group, then we have the state this entry belongs to.
eventmatches = Regex.Split(Script, @"(function \s([^_]+)_event_state_entry[\(\)](?:[^\{]+)?\{)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
int endloop = eventmatches.GetUpperBound(0);
// Add all the states to a list of
List<string> unUsedStates = new List<string>();
foreach (string state in state_events.Keys)
{
unUsedStates.Add(state);
}
// If endloop is 0, then there are no state entry events in the entire script.
// Stick a default state entry in there.
if (endloop == 0)
{
if (state_events.ContainsKey("default"))
{
scriptCopy = "function default_event_state_entry() {osSetStateEvents(" + (int)state_events["default"] + "); } " + Script;
unUsedStates.Remove("default");
}
else
{
throw new Exception("You must define a default state. Compile failed. See LSL documentation for more details.");
}
}
// Loop over state entry events and rewrite the first line to define the events the state listens for.
for (int pos = 0; pos < endloop; pos++)
{
// Returns text before state entry match,
scriptCopy += eventmatches[pos]; pos++;
// Returns text of state entry match,
scriptCopy += eventmatches[pos]; pos++;
// Returns which state we're matching and writes a method call to the end of the above state_entry
scriptCopy += "osSetStateEvents(" + (int)state_events[eventmatches[pos]] + ");"; //pos++;
// Remove the state from the unused list. There might be more states matched then defined, so we
// check if the state was defined first
if (unUsedStates.Contains(eventmatches[pos]))
unUsedStates.Remove(eventmatches[pos]);
// adds the remainder of the script.
if ((pos + 1) == endloop)
{
pos++;
scriptCopy += eventmatches[pos++];
}
}
// states with missing state_entry blocks won't publish their events,
// so, to fix that we write a state entry with only the event publishing method for states missing a state_entry event
foreach (string state in unUsedStates)
{
// Write the remainder states out into a blank state entry with the event setting routine
scriptCopy = "function " + state + "_event_state_entry() {tosSetStateEvents(" + (int)state_events[state] + ");} " + scriptCopy;
}
// save modified script.
unUsedStates.Clear();
state_events.Clear();
return scriptCopy;
}
public static string ReWriteScriptWithPublishedEventsVB(string Script)
{
Dictionary<string, scriptEvents> state_events = new Dictionary<string, scriptEvents>();
// Finds out which events are in the script and writes a method call with the events in each state_entry event
// Note the (?:)? block optional, and not returning a group. Less greedy then .*
string[] eventmatches = new string[0];
//Regex stateevents = new Regex(@"(public void )([^_]+)(_event_)([^\(]+)[\(\)]+\s+[^\{]\{");
eventmatches = Regex.Split(Script, @"Public Sub\s([^_]+)_event_([^\(]+)\((?:[a-zA-Z0-9\s_,\.\-]+)?\)(?:[^()])", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
for (int pos = 0; pos < eventmatches.GetUpperBound(0); pos++)
{
pos++; // garbage
string statea = eventmatches[pos]; pos++;
string eventa = eventmatches[pos];
scriptEvents storedEventsForState = scriptEvents.None;
if (state_events.ContainsKey(statea))
{
storedEventsForState = state_events[statea];
state_events[statea] |= convertnametoFlag(eventa);
}
else
{
state_events.Add(statea, convertnametoFlag(eventa));
}
Console.WriteLine("State:" + statea + ", event: " + eventa);
}
Console.WriteLine("Matches:" + eventmatches.GetUpperBound(0));
// Add namespace, class name and inheritance
// Looking *ONLY* for state entry events
string scriptCopy = "";
//Only match State_Entry events now
// Note the whole regex is a group, then we have the state this entry belongs to.
eventmatches = Regex.Split(Script, @"(Public Sub\s([^_]+)_event_state_entry(?:\s+)?\(\))", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
int endloop = eventmatches.GetUpperBound(0);
// Add all the states to a list of
List<string> unUsedStates = new List<string>();
foreach (string state in state_events.Keys)
{
unUsedStates.Add(state);
}
// If endloop is 0, then there are no state entry events in the entire script.
// Stick a default state entry in there.
if (endloop == 0)
{
if (state_events.ContainsKey("default"))
{
scriptCopy = "function default_event_state_entry() {osSetStateEvents(" + (int)state_events["default"] + "); } " + Script;
unUsedStates.Remove("default");
}
else
{
throw new Exception("You must define a default state. Compile failed. See LSL documentation for more details.");
}
}
// Loop over state entry events and rewrite the first line to define the events the state listens for.
for (int pos = 0; pos < endloop; pos++)
{
// Returns text before state entry match,
scriptCopy += eventmatches[pos]; pos++;
// Returns text of state entry match,
scriptCopy += eventmatches[pos]; pos++;
// Returns which state we're matching and writes a method call to the end of the above state_entry
scriptCopy += "osSetStateEvents(" + (int)state_events[eventmatches[pos]] + ");"; //pos++;
// Remove the state from the unused list. There might be more states matched then defined, so we
// check if the state was defined first
if (unUsedStates.Contains(eventmatches[pos]))
unUsedStates.Remove(eventmatches[pos]);
// adds the remainder of the script.
if ((pos + 1) == endloop)
{
pos++;
scriptCopy += eventmatches[pos++];
}
}
// states with missing state_entry blocks won't publish their events,
// so, to fix that we write a state entry with only the event publishing method for states missing a state_entry event
foreach (string state in unUsedStates)
{
// Write the remainder states out into a blank state entry with the event setting routine
scriptCopy = "function " + state + "_event_state_entry() {tosSetStateEvents(" + (int)state_events[state] + ");} " + scriptCopy;
}
// save modified script.
unUsedStates.Clear();
state_events.Clear();
return scriptCopy;
}
private static scriptEvents convertnametoFlag(string eventname)
{
switch (eventname)
{
case "attach":
return scriptEvents.attach;
//break;
// case "at_rot_target":
//return (long)scriptEvents.at_rot_target;
//break;
case "at_target":
return scriptEvents.at_target;
//break;
//case "changed":
//return (long)scriptEvents.changed;
//break;
case "collision":
return scriptEvents.collision;
// break;
case "collision_end":
return scriptEvents.collision_end;
//break;
case "collision_start":
return scriptEvents.collision_start;
// break;
case "control":
return scriptEvents.control;
//break;
case "dataserver":
return scriptEvents.dataserver;
// break;
case "email":
return scriptEvents.email;
// break;
case "http_response":
return scriptEvents.http_response;
// break;
case "land_collision":
return scriptEvents.land_collision;
// break;
case "land_collision_end":
return scriptEvents.land_collision_end;
// break;
case "land_collision_start":
return scriptEvents.land_collision_start;
// break;
//case "link_message":
//return scriptEvents.link_message;
// break;
case "listen":
return scriptEvents.listen;
// break;
case "money":
return scriptEvents.money;
// break;
case "moving_end":
return scriptEvents.moving_end;
// break;
case "moving_start":
return scriptEvents.moving_start;
// break;
case "not_at_rot_target":
return scriptEvents.not_at_rot_target;
// break;
case "not_at_target":
return scriptEvents.not_at_target;
// break;
// case "no_sensor":
//return (long)scriptEvents.no_sensor;
//break;
//case "on_rez":
//return (long)scriptEvents.on_rez;
// break;
case "remote_data":
return scriptEvents.remote_data;
// break;
case "run_time_permissions":
return scriptEvents.run_time_permissions;
// break;
//case "sensor":
//return (long)scriptEvents.sensor;
// break;
case "state_entry":
return scriptEvents.state_entry;
// break;
case "state_exit":
return scriptEvents.state_exit;
// break;
case "timer":
return scriptEvents.timer;
// break;
case "touch":
return scriptEvents.touch;
// break;
case "touch_end":
return scriptEvents.touch_end;
// break;
case "touch_start":
return scriptEvents.touch_start;
// break;
case "object_rez":
return scriptEvents.object_rez;
default:
return 0;
//break;
}
//return 0;
}
}
[Flags]
public enum scriptEvents : int
{
None = 0,
attach = 1,
collision = 15,
collision_end = 32,
collision_start = 64,
control = 128,
dataserver = 256,
email = 512,
http_response = 1024,
land_collision = 2048,
land_collision_end = 4096,
land_collision_start = 8192,
at_target = 16384,
listen = 32768,
money = 65536,
moving_end = 131072,
moving_start = 262144,
not_at_rot_target = 524288,
not_at_target = 1048576,
remote_data = 8388608,
run_time_permissions = 268435456,
state_entry = 1073741824,
state_exit = 2,
timer = 4,
touch = 8,
touch_end = 536870912,
touch_start = 2097152,
object_rez = 4194304
}
}

View File

@ -42,16 +42,16 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
//private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled); //private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled);
private Dictionary<string, string> dataTypes = new Dictionary<string, string>(); private Dictionary<string, string> dataTypes = new Dictionary<string, string>();
private Dictionary<string, string> quotes = new Dictionary<string, string>(); private Dictionary<string, string> quotes = new Dictionary<string, string>();
private Dictionary<string, scriptEvents> state_events = new Dictionary<string, scriptEvents>();
public LSL2CSConverter() public LSL2CSConverter()
{ {
// Only the types we need to convert // Only the types we need to convert
dataTypes.Add("void", "void"); dataTypes.Add("void", "void");
dataTypes.Add("integer", "int"); dataTypes.Add("integer", "LSL_Types.LSLInteger");
dataTypes.Add("float", "double"); dataTypes.Add("float", "double");
dataTypes.Add("string", "string"); dataTypes.Add("string", "LSL_Types.LSLString");
dataTypes.Add("key", "string"); dataTypes.Add("key", "LSL_Types.LSLString");
dataTypes.Add("vector", "LSL_Types.Vector3"); dataTypes.Add("vector", "LSL_Types.Vector3");
dataTypes.Add("rotation", "LSL_Types.Quaternion"); dataTypes.Add("rotation", "LSL_Types.Quaternion");
dataTypes.Add("list", "LSL_Types.list"); dataTypes.Add("list", "LSL_Types.list");
@ -314,100 +314,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
} }
// Finds out which events are in the script and writes a method call with the events in each state_entry event
// Note the (?:)? block optional, and not returning a group. Less greedy then .*
string[] eventmatches = new string[0];
//Regex stateevents = new Regex(@"(public void )([^_]+)(_event_)([^\(]+)[\(\)]+\s+[^\{]\{");
eventmatches = Regex.Split(Script, @"public void\s([^_]+)_event_([^\(]+)\((?:[a-zA-Z0-9\s_,\.\-]+)?\)(?:[^\{]+)?\{", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
for (int pos = 0; pos<eventmatches.GetUpperBound(0);pos++)
{
pos++; // garbage
string statea = eventmatches[pos]; pos++;
string eventa = eventmatches[pos];
scriptEvents storedEventsForState = scriptEvents.None;
if (state_events.ContainsKey(statea))
{
storedEventsForState = state_events[statea];
state_events[statea] |= convertnametoFlag(eventa);
}
else
{
state_events.Add(statea, convertnametoFlag(eventa));
}
Console.WriteLine("State:" + statea + ", event: " + eventa);
}
Console.WriteLine("Matches:" + eventmatches.GetUpperBound(0));
// Add namespace, class name and inheritance
// Looking *ONLY* for state entry events
string scriptCopy = "";
//Only match State_Entry events now
// Note the whole regex is a group, then we have the state this entry belongs to.
eventmatches = Regex.Split(Script, @"(public void\s([^_]+)_event_state_entry[\(\)](?:[^\{]+)?\{)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
int endloop = eventmatches.GetUpperBound(0);
// Add all the states to a list of
List<string> unUsedStates = new List<string>();
foreach (string state in state_events.Keys)
{
unUsedStates.Add(state);
}
// If endloop is 0, then there are no state entry events in the entire script.
// Stick a default state entry in there.
if (endloop == 0)
{
if (state_events.ContainsKey("default"))
{
scriptCopy = "\r\n// programmatically added this state entry event.\r\n\r\npublic void default_event_state_entry() {\r\n\tosSetStateEvents((int)" + (int)state_events["default"] + ");\r\n }\r\n\r\n " + Script;
unUsedStates.Remove("default");
}
else
{
throw new Exception("You must define a default state. Compile failed. See LSL documentation for more details.");
}
}
// Loop over state entry events and rewrite the first line to define the events the state listens for.
for (int pos = 0; pos < endloop; pos++)
{
// Returns text before state entry match,
scriptCopy += eventmatches[pos]; pos++;
// Returns text of state entry match,
scriptCopy += eventmatches[pos]; pos++;
// Returns which state we're matching and writes a method call to the end of the above state_entry
scriptCopy += "\r\n\t\tosSetStateEvents((int)" + (int)state_events[eventmatches[pos]] + ");"; //pos++;
// Remove the state from the unused list. There might be more states matched then defined, so we
// check if the state was defined first
if (unUsedStates.Contains(eventmatches[pos]))
unUsedStates.Remove(eventmatches[pos]);
// adds the remainder of the script.
if ((pos + 1) == endloop)
{
pos++;
scriptCopy += eventmatches[pos++];
}
}
// states with missing state_entry blocks won't publish their events,
// so, to fix that we write a state entry with only the event publishing method for states missing a state_entry event
foreach (string state in unUsedStates)
{
// Write the remainder states out into a blank state entry with the event setting routine
scriptCopy = "\r\n// programmatically added this state entry event.\r\n\r\npublic void " + state + "_event_state_entry() {\r\n\tosSetStateEvents((int)" + (int)state_events[state] + ");\r\n}\r\n\r\n " + scriptCopy;
}
// save modified script.
Script = scriptCopy;
//System.Console.WriteLine(Script); //System.Console.WriteLine(Script);
Return = String.Empty;// + Return = String.Empty;// +
//"using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;"; //"using OpenSim.Region.ScriptEngine.Common; using System.Collections.Generic;";
@ -421,152 +328,13 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
//Return += @"public Script() { } "; //Return += @"public Script() { } ";
Return += Script; Return += Script;
//Return += "} }\r\n"; //Return += "} }\r\n";
unUsedStates.Clear();
state_events.Clear();
quotes.Clear(); quotes.Clear();
return Return; return Return;
} }
public scriptEvents convertnametoFlag(string eventname)
{
switch (eventname)
{
case "attach":
return scriptEvents.attach;
//break;
// case "at_rot_target":
//return (long)scriptEvents.at_rot_target;
//break;
case "at_target":
return scriptEvents.at_target;
//break;
//case "changed":
//return (long)scriptEvents.changed;
//break;
case "collision":
return scriptEvents.collision;
// break;
case "collision_end":
return scriptEvents.collision_end;
//break;
case "collision_start":
return scriptEvents.collision_start;
// break;
case "control":
return scriptEvents.control;
//break;
case "dataserver":
return scriptEvents.dataserver;
// break;
case "email":
return scriptEvents.email;
// break;
case "http_response":
return scriptEvents.http_response;
// break;
case "land_collision":
return scriptEvents.land_collision;
// break;
case "land_collision_end":
return scriptEvents.land_collision_end;
// break;
case "land_collision_start":
return scriptEvents.land_collision_start;
// break;
//case "link_message":
//return scriptEvents.link_message;
// break;
case "listen":
return scriptEvents.listen;
// break;
case "money":
return scriptEvents.money;
// break;
case "moving_end":
return scriptEvents.moving_end;
// break;
case "moving_start":
return scriptEvents.moving_start;
// break;
case "not_at_rot_target":
return scriptEvents.not_at_rot_target;
// break;
case "not_at_target":
return scriptEvents.not_at_target;
// break;
// case "no_sensor":
//return (long)scriptEvents.no_sensor;
//break;
//case "on_rez":
//return (long)scriptEvents.on_rez;
// break;
case "remote_data":
return scriptEvents.remote_data;
// break;
case "run_time_permissions":
return scriptEvents.run_time_permissions;
// break;
//case "sensor":
//return (long)scriptEvents.sensor;
// break;
case "state_entry":
return scriptEvents.state_entry;
// break;
case "state_exit":
return scriptEvents.state_exit;
// break;
case "timer":
return scriptEvents.timer;
// break;
case "touch":
return scriptEvents.touch;
// break;
case "touch_end":
return scriptEvents.touch_end;
// break;
case "touch_start":
return scriptEvents.touch_start;
// break;
case "object_rez":
return scriptEvents.object_rez;
default:
return 0;
//break;
}
//return 0;
}
} }
[Flags]
public enum scriptEvents : int }
{
None = 0,
attach = 1,
collision = 15,
collision_end = 32,
collision_start = 64,
control = 128,
dataserver = 256,
email = 512,
http_response = 1024,
land_collision = 2048,
land_collision_end = 4096,
land_collision_start = 8192,
at_target = 16384,
listen = 32768,
money = 65536,
moving_end = 131072,
moving_start = 262144,
not_at_rot_target = 524288,
not_at_target = 1048576,
remote_data = 8388608,
run_time_permissions = 268435456,
state_entry = 1073741824,
state_exit = 2,
timer = 4,
touch = 8,
touch_end = 536870912,
touch_start = 2097152,
object_rez = 4194304
}
}