aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
diff options
context:
space:
mode:
authorMelanie Thielker2008-09-23 11:41:34 +0000
committerMelanie Thielker2008-09-23 11:41:34 +0000
commit44e566260c9da5ff62c448cfdd67063c7a486126 (patch)
tree64b9c963872c986317132adc5d4fe0978ad25b64 /OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
parentSmall fix to eliminate a beauty spot (diff)
downloadopensim-SC_OLD-44e566260c9da5ff62c448cfdd67063c7a486126.zip
opensim-SC_OLD-44e566260c9da5ff62c448cfdd67063c7a486126.tar.gz
opensim-SC_OLD-44e566260c9da5ff62c448cfdd67063c7a486126.tar.bz2
opensim-SC_OLD-44e566260c9da5ff62c448cfdd67063c7a486126.tar.xz
Mantis #2243
Thank you, tyre, for a patch that refactors LSL to use a unified set of method signatures and type names, reorders methods and removes unused and adds new method stubs.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/LSL_Types.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_Types.cs147
1 files changed, 123 insertions, 24 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
index bff2101..21646ea 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
@@ -123,7 +123,7 @@ namespace OpenSim.Region.ScriptEngine.Common
123 123
124 Vector3 vector = (Vector3)o; 124 Vector3 vector = (Vector3)o;
125 125
126 return (x == vector.x && y == vector.y && z == vector.y); 126 return (x == vector.x && y == vector.y && z == vector.z);
127 } 127 }
128 128
129 public static Vector3 operator -(Vector3 vector) 129 public static Vector3 operator -(Vector3 vector)
@@ -419,6 +419,80 @@ namespace OpenSim.Region.ScriptEngine.Common
419 m_data=new Object[0]; 419 m_data=new Object[0];
420 return m_data; 420 return m_data;
421 } 421 }
422
423 set {m_data = value; }
424 }
425
426 // Member functions to obtain item as specific types.
427 // For cases where implicit conversions would apply if items
428 // were not in a list (e.g. integer to float, but not float
429 // to integer) functions check for alternate types so as to
430 // down-cast from Object to the correct type.
431 // Note: no checks for item index being valid are performed
432
433 public LSL_Types.LSLFloat GetLSLFloatItem( int itemIndex )
434 {
435 if (m_data[itemIndex] is LSL_Types.LSLInteger)
436 {
437 return (LSL_Types.LSLInteger)m_data[itemIndex];
438 }
439 else if (m_data[itemIndex] is Int32)
440 {
441 return new LSL_Types.LSLFloat((int)m_data[itemIndex]);
442 }
443 else if (m_data[itemIndex] is float)
444 {
445 return new LSL_Types.LSLFloat((float)m_data[itemIndex]);
446 }
447 else if (m_data[itemIndex] is Double)
448 {
449 return new LSL_Types.LSLFloat((Double)m_data[itemIndex]);
450 }
451 else
452 {
453 return (LSL_Types.LSLFloat)m_data[itemIndex];
454 }
455 }
456
457 public LSL_Types.LSLString GetLSLStringItem(int itemIndex)
458 {
459 if (m_data[itemIndex] is LSL_Types.key)
460 {
461 return (LSL_Types.key)m_data[itemIndex];
462 }
463 else if (m_data[itemIndex] is String)
464 {
465 return new LSL_Types.LSLString((string)m_data[itemIndex]);
466 }
467 else
468 {
469 return (LSL_Types.LSLString)m_data[itemIndex];
470 }
471 }
472
473 public LSL_Types.LSLInteger GetLSLIntegerItem(int itemIndex)
474 {
475 if (m_data[itemIndex] is LSL_Types.LSLInteger)
476 return (LSL_Types.LSLInteger)m_data[itemIndex];
477 else if (m_data[itemIndex] is Int32)
478 return new LSLInteger((int)m_data[itemIndex]);
479 else
480 throw new InvalidCastException();
481 }
482
483 public LSL_Types.Vector3 GetVector3Item(int itemIndex)
484 {
485 return (LSL_Types.Vector3)m_data[itemIndex];
486 }
487
488 public LSL_Types.Quaternion GetQuaternionItem(int itemIndex)
489 {
490 return (LSL_Types.Quaternion)m_data[itemIndex];
491 }
492
493 public LSL_Types.key GetKeyItem(int itemIndex)
494 {
495 return (LSL_Types.key)m_data[itemIndex];
422 } 496 }
423 497
424 public static list operator +(list a, list b) 498 public static list operator +(list a, list b)
@@ -436,19 +510,19 @@ namespace OpenSim.Region.ScriptEngine.Common
436 m_data.SetValue(o, Length - 1); 510 m_data.SetValue(o, Length - 1);
437 } 511 }
438 512
439 public static list operator +(list a, string s) 513 public static list operator +(list a, LSLString s)
440 { 514 {
441 a.ExtendAndAdd(s); 515 a.ExtendAndAdd(s);
442 return a; 516 return a;
443 } 517 }
444 518
445 public static list operator +(list a, int i) 519 public static list operator +(list a, LSLInteger i)
446 { 520 {
447 a.ExtendAndAdd(i); 521 a.ExtendAndAdd(i);
448 return a; 522 return a;
449 } 523 }
450 524
451 public static list operator +(list a, double d) 525 public static list operator +(list a, LSLFloat d)
452 { 526 {
453 a.ExtendAndAdd(d); 527 a.ExtendAndAdd(d);
454 return a; 528 return a;
@@ -1167,6 +1241,11 @@ namespace OpenSim.Region.ScriptEngine.Common
1167 return k.value; 1241 return k.value;
1168 } 1242 }
1169 1243
1244 static public implicit operator LSLString(key k)
1245 {
1246 return k.value;
1247 }
1248
1170 public static bool operator ==(key k1, key k2) 1249 public static bool operator ==(key k1, key k2)
1171 { 1250 {
1172 return k1.value == k2.value; 1251 return k1.value == k2.value;
@@ -1190,6 +1269,11 @@ namespace OpenSim.Region.ScriptEngine.Common
1190 return value.GetHashCode(); 1269 return value.GetHashCode();
1191 } 1270 }
1192 1271
1272 public override string ToString()
1273 {
1274 return value;
1275 }
1276
1193 #endregion 1277 #endregion
1194 } 1278 }
1195 1279
@@ -1476,25 +1560,25 @@ namespace OpenSim.Region.ScriptEngine.Common
1476 return new LSLInteger(i1.value / i2); 1560 return new LSLInteger(i1.value / i2);
1477 } 1561 }
1478 1562
1479 static public LSLFloat operator +(LSLInteger i1, double f) 1563// static public LSLFloat operator +(LSLInteger i1, double f)
1480 { 1564// {
1481 return new LSLFloat((double)i1.value + f); 1565// return new LSLFloat((double)i1.value + f);
1482 } 1566// }
1483 1567//
1484 static public LSLFloat operator -(LSLInteger i1, double f) 1568// static public LSLFloat operator -(LSLInteger i1, double f)
1485 { 1569// {
1486 return new LSLFloat((double)i1.value - f); 1570// return new LSLFloat((double)i1.value - f);
1487 } 1571// }
1488 1572//
1489 static public LSLFloat operator *(LSLInteger i1, double f) 1573// static public LSLFloat operator *(LSLInteger i1, double f)
1490 { 1574// {
1491 return new LSLFloat((double)i1.value * f); 1575// return new LSLFloat((double)i1.value * f);
1492 } 1576// }
1493 1577//
1494 static public LSLFloat operator /(LSLInteger i1, double f) 1578// static public LSLFloat operator /(LSLInteger i1, double f)
1495 { 1579// {
1496 return new LSLFloat((double)i1.value / f); 1580// return new LSLFloat((double)i1.value / f);
1497 } 1581// }
1498 1582
1499 static public LSLInteger operator -(LSLInteger i) 1583 static public LSLInteger operator -(LSLInteger i)
1500 { 1584 {
@@ -1585,6 +1669,11 @@ namespace OpenSim.Region.ScriptEngine.Common
1585 1669
1586 #region Operators 1670 #region Operators
1587 1671
1672 static public explicit operator float(LSLFloat f)
1673 {
1674 return (float)f.value;
1675 }
1676
1588 static public explicit operator int(LSLFloat f) 1677 static public explicit operator int(LSLFloat f)
1589 { 1678 {
1590 return (int)f.value; 1679 return (int)f.value;
@@ -1619,7 +1708,17 @@ namespace OpenSim.Region.ScriptEngine.Common
1619 1708
1620 static public explicit operator LSLFloat(string s) 1709 static public explicit operator LSLFloat(string s)
1621 { 1710 {
1622 return new LSLFloat(double.Parse(s)); 1711 Regex r = new Regex("^[ ]*-?[0-9]*\\.?[0-9]*[eE]?-?[0-9]*");
1712 Match m = r.Match(s);
1713 string v = m.Groups[0].Value;
1714
1715 while (v.Length > 0 && v.Substring(0, 1) == " ")
1716 v = v.Substring(1);
1717
1718 if (v == String.Empty)
1719 v = "0";
1720
1721 return new LSLFloat(double.Parse(v));
1623 } 1722 }
1624 1723
1625 static public implicit operator LSLFloat(double d) 1724 static public implicit operator LSLFloat(double d)