diff options
author | Teravus Ovares | 2008-04-30 03:36:13 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-04-30 03:36:13 +0000 |
commit | 36bf16d35e928a338c932feeec42c0c8f35d8846 (patch) | |
tree | 06f11a4c546fce85fe1504fce08a09dd4bdebb06 /OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | |
parent | * Disabled IntergridModule until a Mono bug can be isolated. (diff) | |
download | opensim-SC_OLD-36bf16d35e928a338c932feeec42c0c8f35d8846.zip opensim-SC_OLD-36bf16d35e928a338c932feeec42c0c8f35d8846.tar.gz opensim-SC_OLD-36bf16d35e928a338c932feeec42c0c8f35d8846.tar.bz2 opensim-SC_OLD-36bf16d35e928a338c932feeec42c0c8f35d8846.tar.xz |
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.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/LSL_Types.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | 176 |
1 files changed, 124 insertions, 52 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs index 65047fb..5337d7f 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | |||
@@ -64,6 +64,11 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
64 | str = str.Replace('<', ' '); | 64 | str = str.Replace('<', ' '); |
65 | str = str.Replace('>', ' '); | 65 | str = str.Replace('>', ' '); |
66 | string[] tmps = str.Split(new Char[] { ',', '<', '>' }); | 66 | string[] tmps = str.Split(new Char[] { ',', '<', '>' }); |
67 | if(tmps.Length < 3) | ||
68 | { | ||
69 | x=y=z=0; | ||
70 | return; | ||
71 | } | ||
67 | bool res; | 72 | bool res; |
68 | res = Double.TryParse(tmps[0], out x); | 73 | res = Double.TryParse(tmps[0], out x); |
69 | res = res & Double.TryParse(tmps[1], out y); | 74 | res = res & Double.TryParse(tmps[1], out y); |
@@ -76,14 +81,27 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
76 | 81 | ||
77 | public override string ToString() | 82 | public override string ToString() |
78 | { | 83 | { |
79 | return "<" + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ">"; | 84 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", x, y, z); |
85 | return s; | ||
86 | } | ||
87 | |||
88 | public static explicit operator LSLString(Vector3 vec) | ||
89 | { | ||
90 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); | ||
91 | return new LSLString(s); | ||
80 | } | 92 | } |
81 | 93 | ||
82 | public static explicit operator string(Vector3 vec) | 94 | public static explicit operator string(Vector3 vec) |
83 | { | 95 | { |
84 | return "<" + vec.x.ToString() + ", " + vec.y.ToString() + ", " + vec.z.ToString() + ">"; | 96 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000}>", vec.x, vec.y, vec.z); |
97 | return s; | ||
85 | } | 98 | } |
86 | 99 | ||
100 | public static explicit operator Vector3(string s) | ||
101 | { | ||
102 | return new Vector3(s); | ||
103 | } | ||
104 | |||
87 | public static bool operator ==(Vector3 lhs, Vector3 rhs) | 105 | public static bool operator ==(Vector3 lhs, Vector3 rhs) |
88 | { | 106 | { |
89 | return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z); | 107 | return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z); |
@@ -278,6 +296,11 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
278 | str = str.Replace('<', ' '); | 296 | str = str.Replace('<', ' '); |
279 | str = str.Replace('>', ' '); | 297 | str = str.Replace('>', ' '); |
280 | string[] tmps = str.Split(new Char[] { ',', '<', '>' }); | 298 | string[] tmps = str.Split(new Char[] { ',', '<', '>' }); |
299 | if(tmps.Length < 4) | ||
300 | { | ||
301 | x=y=z=s=0; | ||
302 | return; | ||
303 | } | ||
281 | bool res; | 304 | bool res; |
282 | res = Double.TryParse(tmps[0], out x); | 305 | res = Double.TryParse(tmps[0], out x); |
283 | res = res & Double.TryParse(tmps[1], out y); | 306 | res = res & Double.TryParse(tmps[1], out y); |
@@ -307,14 +330,27 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
307 | 330 | ||
308 | public override string ToString() | 331 | public override string ToString() |
309 | { | 332 | { |
310 | return "<" + x.ToString() + ", " + y.ToString() + ", " + z.ToString() + ", " + s.ToString() + ">"; | 333 | string st=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", x, y, z, s); |
334 | return st; | ||
311 | } | 335 | } |
312 | 336 | ||
313 | public static explicit operator string(Quaternion r) | 337 | public static explicit operator string(Quaternion r) |
314 | { | 338 | { |
315 | return "<" + r.x.ToString() + ", " + r.y.ToString() + ", " + r.z.ToString() + ", " + r.s.ToString() + ">"; | 339 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); |
340 | return s; | ||
341 | } | ||
342 | |||
343 | public static explicit operator LSLString(Quaternion r) | ||
344 | { | ||
345 | string s=String.Format("<{0:0.000000},{1:0.000000},{2:0.000000},{3:0.000000}>", r.x, r.y, r.z, r.s); | ||
346 | return new LSLString(s); | ||
316 | } | 347 | } |
317 | 348 | ||
349 | public static explicit operator Quaternion(string s) | ||
350 | { | ||
351 | return new Quaternion(s); | ||
352 | } | ||
353 | |||
318 | public static bool operator ==(Quaternion lhs, Quaternion rhs) | 354 | public static bool operator ==(Quaternion lhs, Quaternion rhs) |
319 | { | 355 | { |
320 | // Return true if the fields match: | 356 | // Return true if the fields match: |
@@ -369,12 +405,20 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
369 | 405 | ||
370 | public int Length | 406 | public int Length |
371 | { | 407 | { |
372 | get { return m_data.Length; } | 408 | get { |
409 | if(m_data == null) | ||
410 | m_data=new Object[0]; | ||
411 | return m_data.Length; | ||
412 | } | ||
373 | } | 413 | } |
374 | 414 | ||
375 | public object[] Data | 415 | public object[] Data |
376 | { | 416 | { |
377 | get { return m_data; } | 417 | get { |
418 | if(m_data == null) | ||
419 | m_data=new Object[0]; | ||
420 | return m_data; | ||
421 | } | ||
378 | } | 422 | } |
379 | 423 | ||
380 | public static list operator +(list a, list b) | 424 | public static list operator +(list a, list b) |
@@ -571,13 +615,20 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
571 | if(Data.Length == 0) | 615 | if(Data.Length == 0) |
572 | return new list(); // Don't even bother | 616 | return new list(); // Don't even bother |
573 | 617 | ||
618 | string[] keys; | ||
619 | |||
574 | if(stride == 1) // The simple case | 620 | if(stride == 1) // The simple case |
575 | { | 621 | { |
576 | Object[] ret=new Object[Data.Length]; | 622 | Object[] ret=new Object[Data.Length]; |
577 | 623 | ||
578 | Array.Copy(Data, 0, ret, 0, Data.Length); | 624 | Array.Copy(Data, 0, ret, 0, Data.Length); |
579 | 625 | ||
580 | Array.Sort(ret); | 626 | keys=new string[Data.Length]; |
627 | int k; | ||
628 | for(k=0;k<Data.Length;k++) | ||
629 | keys[k]=Data[k].ToString(); | ||
630 | |||
631 | Array.Sort(keys, ret); | ||
581 | 632 | ||
582 | if(ascending == 0) | 633 | if(ascending == 0) |
583 | Array.Reverse(ret); | 634 | Array.Reverse(ret); |
@@ -588,7 +639,7 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
588 | 639 | ||
589 | int len=(Data.Length+stride-1)/stride; | 640 | int len=(Data.Length+stride-1)/stride; |
590 | 641 | ||
591 | string[] keys=new string[len]; | 642 | keys=new string[len]; |
592 | Object[][] vals=new Object[len][]; | 643 | Object[][] vals=new Object[len][]; |
593 | 644 | ||
594 | int i; | 645 | int i; |
@@ -1016,17 +1067,7 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1016 | 1067 | ||
1017 | public override bool Equals(object o) | 1068 | public override bool Equals(object o) |
1018 | { | 1069 | { |
1019 | if (o is String) | 1070 | return o.ToString() == value; |
1020 | { | ||
1021 | string s = (string)o; | ||
1022 | return s == this.value; | ||
1023 | } | ||
1024 | if (o is key) | ||
1025 | { | ||
1026 | key k = (key)o; | ||
1027 | return this.value == k.value; | ||
1028 | } | ||
1029 | return false; | ||
1030 | } | 1071 | } |
1031 | 1072 | ||
1032 | public override int GetHashCode() | 1073 | public override int GetHashCode() |
@@ -1046,6 +1087,13 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1046 | { | 1087 | { |
1047 | m_string = s; | 1088 | m_string = s; |
1048 | } | 1089 | } |
1090 | |||
1091 | public LSLString(double d) | ||
1092 | { | ||
1093 | string s=String.Format("{0:0.000000}", d); | ||
1094 | m_string=s; | ||
1095 | } | ||
1096 | |||
1049 | #endregion | 1097 | #endregion |
1050 | 1098 | ||
1051 | #region Operators | 1099 | #region Operators |
@@ -1071,44 +1119,47 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1071 | return new LSLString(s); | 1119 | return new LSLString(s); |
1072 | } | 1120 | } |
1073 | 1121 | ||
1074 | // Commented out: | 1122 | public static string ToString(LSLString s) |
1075 | /* | 1123 | { |
1076 | [echo] Build Directory is /home/tedd/opensim/trunk/OpenSim/Region/ScriptEngine/Common/bin/Debug | 1124 | return s.m_string; |
1077 | [csc] Compiling 5 files to '/home/tedd/opensim/trunk/OpenSim/Region/ScriptEngine/Common/bin/Debug/OpenSim.Region.ScriptEngine.Common.dll'. | 1125 | } |
1078 | [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)' | 1126 | |
1079 | [csc] /home/tedd/opensim/trunk/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs(602,32): (Location of the symbol related to previous error) | 1127 | public override string ToString() |
1080 | [csc] /usr/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error) | 1128 | { |
1081 | [csc] Compilation failed: 1 error(s), 0 warnings | 1129 | return m_string; |
1082 | */ | 1130 | } |
1083 | //public static bool operator ==(LSLString s1, LSLString s2) | 1131 | |
1084 | //{ | 1132 | public static bool operator ==(LSLString s1, string s2) |
1085 | // return s1.m_string == s2.m_string; | 1133 | { |
1086 | //} | 1134 | return s1.m_string == s2; |
1087 | //public static bool operator !=(LSLString s1, LSLString s2) | 1135 | } |
1088 | //{ | 1136 | |
1089 | // return s1.m_string != s2.m_string; | 1137 | public static bool operator !=(LSLString s1, string s2) |
1090 | //} | 1138 | { |
1139 | return s1.m_string != s2; | ||
1140 | } | ||
1141 | |||
1142 | public static explicit operator double(LSLString s) | ||
1143 | { | ||
1144 | return Convert.ToDouble(s.m_string); | ||
1145 | } | ||
1146 | |||
1147 | public static explicit operator LSLInteger(LSLString s) | ||
1148 | { | ||
1149 | return new LSLInteger(Convert.ToInt32(s.m_string)); | ||
1150 | } | ||
1151 | |||
1152 | public static explicit operator LSLString(double d) | ||
1153 | { | ||
1154 | return new LSLString(d); | ||
1155 | } | ||
1156 | |||
1091 | #endregion | 1157 | #endregion |
1092 | 1158 | ||
1093 | #region Overriders | 1159 | #region Overriders |
1094 | public override bool Equals(object o) | 1160 | public override bool Equals(object o) |
1095 | { | 1161 | { |
1096 | if (o is String) | 1162 | return m_string == o.ToString(); |
1097 | { | ||
1098 | string s = (string)o; | ||
1099 | return s == this.m_string; | ||
1100 | } | ||
1101 | if (o is key) | ||
1102 | { | ||
1103 | key k = (key)o; | ||
1104 | return this.m_string == k.value; | ||
1105 | } | ||
1106 | if (o is LSLString) | ||
1107 | { | ||
1108 | LSLString s = (string)o; | ||
1109 | return this.m_string == s; | ||
1110 | } | ||
1111 | return false; | ||
1112 | } | 1163 | } |
1113 | 1164 | ||
1114 | public override int GetHashCode() | 1165 | public override int GetHashCode() |
@@ -1154,6 +1205,11 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1154 | return i.value; | 1205 | return i.value; |
1155 | } | 1206 | } |
1156 | 1207 | ||
1208 | static public explicit operator LSLString(LSLInteger i) | ||
1209 | { | ||
1210 | return new LSLString(i.ToString()); | ||
1211 | } | ||
1212 | |||
1157 | static public implicit operator Boolean(LSLInteger i) | 1213 | static public implicit operator Boolean(LSLInteger i) |
1158 | { | 1214 | { |
1159 | if (i.value == 0) | 1215 | if (i.value == 0) |
@@ -1171,6 +1227,11 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1171 | return new LSLInteger(i); | 1227 | return new LSLInteger(i); |
1172 | } | 1228 | } |
1173 | 1229 | ||
1230 | static public explicit operator LSLInteger(string s) | ||
1231 | { | ||
1232 | return new LSLInteger(int.Parse(s)); | ||
1233 | } | ||
1234 | |||
1174 | static public implicit operator LSLInteger(double d) | 1235 | static public implicit operator LSLInteger(double d) |
1175 | { | 1236 | { |
1176 | return new LSLInteger(d); | 1237 | return new LSLInteger(d); |
@@ -1182,6 +1243,17 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1182 | return ret; | 1243 | return ret; |
1183 | } | 1244 | } |
1184 | 1245 | ||
1246 | public static LSLInteger operator ++(LSLInteger i) | ||
1247 | { | ||
1248 | i.value++; | ||
1249 | return i; | ||
1250 | } | ||
1251 | |||
1252 | public static LSLInteger operator --(LSLInteger i) | ||
1253 | { | ||
1254 | i.value--; | ||
1255 | return i; | ||
1256 | } | ||
1185 | 1257 | ||
1186 | //static public implicit operator System.Double(LSLInteger i) | 1258 | //static public implicit operator System.Double(LSLInteger i) |
1187 | //{ | 1259 | //{ |