diff options
author | Charles Krinke | 2008-09-05 23:26:35 +0000 |
---|---|---|
committer | Charles Krinke | 2008-09-05 23:26:35 +0000 |
commit | 947242f4764b8d98fe860d3c18bcea709aea777f (patch) | |
tree | 2169a26250473aa887dac6f492b582e779d41639 /OpenSim | |
parent | Thank you kindly, KrTaylor for a patch that adds: (diff) | |
download | opensim-SC_OLD-947242f4764b8d98fe860d3c18bcea709aea777f.zip opensim-SC_OLD-947242f4764b8d98fe860d3c18bcea709aea777f.tar.gz opensim-SC_OLD-947242f4764b8d98fe860d3c18bcea709aea777f.tar.bz2 opensim-SC_OLD-947242f4764b8d98fe860d3c18bcea709aea777f.tar.xz |
Mantis#2126. Thank you kindly, Ralphos for a patch that addresses:
Types extracted from a LSL_Types.list have to be down-cast initially
to the exact type of value type object that the Object actually is.
This would make for very cumbersome, ugly code when extracting list
parameter items in ll functions where a few implicit conversions
should be applied such as key -> LSLString and LSLInteger -> LSLFloat
(but not LSLFloat -> LSLInteger). This patch adds a set of GetXXXItem
member functions to the LLS_Type.list class, where XXX is the name
of the LSL_Type to be extracted: LSLFLoat, LSLInteger etc. All take
a single, int parameter that is the item number to be extracted.
Diffstat (limited to 'OpenSim')
3 files changed, 169 insertions, 8 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 74c2d89..93dfeea 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -5726,13 +5726,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
5726 | if (remain < 7) | 5726 | if (remain < 7) |
5727 | return; | 5727 | return; |
5728 | 5728 | ||
5729 | bool flexi = (LSL_Types.LSLInteger)rules.Data[idx++]; | 5729 | bool flexi = rules.GetLSLIntegerItem(idx++); |
5730 | int softness = (LSL_Types.LSLInteger)rules.Data[idx++]; | 5730 | int softness = rules.GetLSLIntegerItem(idx++); |
5731 | float gravity = (float)(LSL_Types.LSLFloat)rules.Data[idx++]; | 5731 | float gravity = (float)rules.GetLSLFloatItem(idx++); |
5732 | float friction = (float)(LSL_Types.LSLFloat)rules.Data[idx++]; | 5732 | float friction = (float)rules.GetLSLFloatItem(idx++); |
5733 | float wind = (float)(LSL_Types.LSLFloat)rules.Data[idx++]; | 5733 | float wind = (float)rules.GetLSLFloatItem(idx++); |
5734 | float tension = (float)(LSL_Types.LSLFloat)rules.Data[idx++]; | 5734 | float tension = (float)rules.GetLSLFloatItem(idx++); |
5735 | LSL_Types.Vector3 force = (LSL_Types.Vector3)rules.Data[idx++]; | 5735 | LSL_Types.Vector3 force = rules.GetVector3Item(idx++); |
5736 | 5736 | ||
5737 | SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force); | 5737 | SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force); |
5738 | 5738 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 85abdb0..4713283 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | |||
@@ -421,6 +421,58 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
421 | } | 421 | } |
422 | } | 422 | } |
423 | 423 | ||
424 | // Member functions to obtain item as specific types. | ||
425 | // For cases where implicit conversions would apply if items | ||
426 | // were not in a list (e.g. integer to float, but not float | ||
427 | // to integer) functions check for alternate types so as to | ||
428 | // down-cast from Object to the correct type. | ||
429 | // Note: no checks for item index being valid are performed | ||
430 | |||
431 | public LSL_Types.LSLFloat GetLSLFloatItem( int itemIndex ) | ||
432 | { | ||
433 | if (m_data[itemIndex] is LSL_Types.LSLInteger) | ||
434 | { | ||
435 | return (LSL_Types.LSLInteger)m_data[itemIndex]; | ||
436 | } | ||
437 | else | ||
438 | { | ||
439 | return (LSL_Types.LSLFloat)m_data[itemIndex]; | ||
440 | } | ||
441 | } | ||
442 | |||
443 | public LSL_Types.LSLString GetLSLStringItem(int itemIndex) | ||
444 | { | ||
445 | if (m_data[itemIndex] is LSL_Types.key) | ||
446 | { | ||
447 | return (LSL_Types.key)m_data[itemIndex]; | ||
448 | } | ||
449 | else | ||
450 | { | ||
451 | return (LSL_Types.LSLString)m_data[itemIndex]; | ||
452 | } | ||
453 | } | ||
454 | |||
455 | public LSL_Types.LSLInteger GetLSLIntegerItem(int itemIndex) | ||
456 | { | ||
457 | return (LSL_Types.LSLInteger)m_data[itemIndex]; | ||
458 | } | ||
459 | |||
460 | public LSL_Types.Vector3 GetVector3Item(int itemIndex) | ||
461 | { | ||
462 | return (LSL_Types.Vector3)m_data[itemIndex]; | ||
463 | } | ||
464 | |||
465 | public LSL_Types.Quaternion GetQuaternionItem(int itemIndex) | ||
466 | { | ||
467 | return (LSL_Types.Quaternion)m_data[itemIndex]; | ||
468 | } | ||
469 | |||
470 | public LSL_Types.key GetKeyItem(int itemIndex) | ||
471 | { | ||
472 | return (LSL_Types.key)m_data[itemIndex]; | ||
473 | } | ||
474 | |||
475 | |||
424 | public static list operator +(list a, list b) | 476 | public static list operator +(list a, list b) |
425 | { | 477 | { |
426 | object[] tmp; | 478 | object[] tmp; |
@@ -1164,7 +1216,12 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
1164 | 1216 | ||
1165 | static public implicit operator String(key k) | 1217 | static public implicit operator String(key k) |
1166 | { | 1218 | { |
1167 | return k.value; | 1219 | return k.value; |
1220 | } | ||
1221 | |||
1222 | static public implicit operator LSLString(key k) | ||
1223 | { | ||
1224 | return k.value; | ||
1168 | } | 1225 | } |
1169 | 1226 | ||
1170 | public static bool operator ==(key k1, key k2) | 1227 | public static bool operator ==(key k1, key k2) |
@@ -1190,6 +1247,11 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
1190 | return value.GetHashCode(); | 1247 | return value.GetHashCode(); |
1191 | } | 1248 | } |
1192 | 1249 | ||
1250 | public override string ToString() | ||
1251 | { | ||
1252 | return value; | ||
1253 | } | ||
1254 | |||
1193 | #endregion | 1255 | #endregion |
1194 | } | 1256 | } |
1195 | 1257 | ||
diff --git a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestList.cs b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestList.cs index 9e8d716..ca59c97 100644 --- a/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestList.cs +++ b/OpenSim/Tests/Region/ScriptEngine/Shared/LSL_TypesTestList.cs | |||
@@ -157,6 +157,105 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
157 | Assert.AreEqual(testValue, (LSL_Types.Quaternion)testList.Data[0]); | 157 | Assert.AreEqual(testValue, (LSL_Types.Quaternion)testList.Data[0]); |
158 | } | 158 | } |
159 | 159 | ||
160 | //==================================================================================== | ||
160 | 161 | ||
162 | /// <summary> | ||
163 | /// Tests GetLSLIntegerItem for LSLInteger item. | ||
164 | /// </summary> | ||
165 | [Test] | ||
166 | public void TestGetLSLIntegerItemForLSLIntegerItem() | ||
167 | { | ||
168 | LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(999911); | ||
169 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
170 | |||
171 | Assert.AreEqual(testValue, testList.GetLSLIntegerItem(0)); | ||
172 | } | ||
173 | |||
174 | /// <summary> | ||
175 | /// Tests GetLSLFloatItem for LSLFloat item. | ||
176 | /// </summary> | ||
177 | [Test] | ||
178 | public void TestGetLSLFloatItemForLSLFloatItem() | ||
179 | { | ||
180 | LSL_Types.LSLFloat testValue = new LSL_Types.LSLFloat(321.45687876); | ||
181 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
182 | |||
183 | Assert.AreEqual(testValue, testList.GetLSLFloatItem(0)); | ||
184 | } | ||
185 | |||
186 | /// <summary> | ||
187 | /// Tests GetLSLFloatItem for LSLInteger item. | ||
188 | /// </summary> | ||
189 | [Test] | ||
190 | public void TestGetLSLFloatItemForLSLIntegerItem() | ||
191 | { | ||
192 | LSL_Types.LSLInteger testValue = new LSL_Types.LSLInteger(3060987); | ||
193 | LSL_Types.LSLFloat testFloatValue = new LSL_Types.LSLFloat(testValue); | ||
194 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
195 | |||
196 | Assert.AreEqual(testFloatValue, testList.GetLSLFloatItem(0)); | ||
197 | } | ||
198 | |||
199 | /// <summary> | ||
200 | /// Tests GetLSLStringItem for LSLString item. | ||
201 | /// </summary> | ||
202 | [Test] | ||
203 | public void TestGetLSLStringItemForLSLStringItem() | ||
204 | { | ||
205 | LSL_Types.LSLString testValue = new LSL_Types.LSLString("hello all"); | ||
206 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
207 | |||
208 | Assert.AreEqual(testValue, testList.GetLSLStringItem(0)); | ||
209 | } | ||
210 | |||
211 | /// <summary> | ||
212 | /// Tests GetLSLStringItem for key item. | ||
213 | /// </summary> | ||
214 | [Test] | ||
215 | public void TestGetLSLStringItemForKeyItem() | ||
216 | { | ||
217 | LSL_Types.key testValue | ||
218 | = new LSL_Types.key("98000000-0000-2222-3333-100000001000"); | ||
219 | LSL_Types.LSLString testStringValue = new LSL_Types.LSLString(testValue); | ||
220 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
221 | |||
222 | Assert.AreEqual(testStringValue, testList.GetLSLStringItem(0)); | ||
223 | } | ||
224 | |||
225 | /// <summary> | ||
226 | /// Tests GetVector3Item for Vector3 item. | ||
227 | /// </summary> | ||
228 | [Test] | ||
229 | public void TestGetVector3ItemForVector3Item() | ||
230 | { | ||
231 | LSL_Types.Vector3 testValue = new LSL_Types.Vector3(92.34, 58.98754, -0.10987); | ||
232 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
233 | |||
234 | Assert.AreEqual(testValue, testList.GetVector3Item(0)); | ||
235 | } | ||
236 | /// <summary> | ||
237 | /// Tests GetQuaternionItem for Quaternion item. | ||
238 | /// </summary> | ||
239 | [Test] | ||
240 | public void TestGetQuaternionItemForQuaternionItem() | ||
241 | { | ||
242 | LSL_Types.Quaternion testValue = new LSL_Types.Quaternion(12.64, 59.43723, 765.3421, 4.00987); | ||
243 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
244 | |||
245 | Assert.AreEqual(testValue, testList.GetQuaternionItem(0)); | ||
246 | } | ||
247 | |||
248 | /// <summary> | ||
249 | /// Tests GetKeyItem for key item. | ||
250 | /// </summary> | ||
251 | [Test] | ||
252 | public void TestGetKeyItemForKeyItem() | ||
253 | { | ||
254 | LSL_Types.key testValue | ||
255 | = new LSL_Types.key("00000000-0000-2222-3333-100000001012"); | ||
256 | LSL_Types.list testList = new LSL_Types.list(testValue); | ||
257 | |||
258 | Assert.AreEqual(testValue, testList.GetKeyItem(0)); | ||
259 | } | ||
161 | } | 260 | } |
162 | } | 261 | } |