diff options
author | Mike Mazur | 2008-07-31 07:11:41 +0000 |
---|---|---|
committer | Mike Mazur | 2008-07-31 07:11:41 +0000 |
commit | 57ec7a26cda361eeac9d7f010194cfe0dfa6c281 (patch) | |
tree | eb8bb3680e3cb7db5449c3703835e6454e43ebbb | |
parent | Allow assignments in if/while/do-while control statements. Fix issue 1862. (diff) | |
download | opensim-SC-57ec7a26cda361eeac9d7f010194cfe0dfa6c281.zip opensim-SC-57ec7a26cda361eeac9d7f010194cfe0dfa6c281.tar.gz opensim-SC-57ec7a26cda361eeac9d7f010194cfe0dfa6c281.tar.bz2 opensim-SC-57ec7a26cda361eeac9d7f010194cfe0dfa6c281.tar.xz |
-make ZERO_VECTOR and ZERO_ROTATION static readonly properties so they can be
used in scripts
-cast from bool to LSL{Integer,Float,String} so functions such as `integer
isZero(integer x) { return (x == 0); }` work
-progress on issue 1863
11 files changed, 180 insertions, 6 deletions
diff --git a/OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs b/OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs index 1db1446..b03e761 100644 --- a/OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs +++ b/OpenSim/Grid/ScriptEngine/DotNetEngine/Compiler/LSL/LSL_BaseClass.cs | |||
@@ -2118,7 +2118,7 @@ namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL | |||
2118 | public const int PUBLIC_CHANNEL 0x00000000 | 2118 | public const int PUBLIC_CHANNEL 0x00000000 |
2119 | 2119 | ||
2120 | // Can not be public const? | 2120 | // Can not be public const? |
2121 | public vector ZERO_VECTOR = new vector(0, 0, 0); | 2121 | public static readonly vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0); |
2122 | public rotation ZERO_ROTATION = new rotation(0, 0, 0, 0); | 2122 | public static readonly rotation ZERO_ROTATION = new rotation(0.0, 0.0, 0.0, 1.0); |
2123 | } | 2123 | } |
2124 | } | 2124 | } |
diff --git a/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs b/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs index 9dd7e01..575cb43 100644 --- a/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs +++ b/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs | |||
@@ -2421,7 +2421,7 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
2421 | public const int OBJECT_CREATOR = 8; | 2421 | public const int OBJECT_CREATOR = 8; |
2422 | 2422 | ||
2423 | // Can not be public const? | 2423 | // Can not be public const? |
2424 | public vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0); | 2424 | public static readonly vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0); |
2425 | public rotation ZERO_ROTATION = new rotation(0.0, 0, 0.0, 1.0); | 2425 | public static readonly rotation ZERO_ROTATION = new rotation(0.0, 0, 0.0, 1.0); |
2426 | } | 2426 | } |
2427 | } | 2427 | } |
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs index b8a4a4d..21acac2 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | |||
@@ -1186,6 +1186,14 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1186 | return new LSLString(f); | 1186 | return new LSLString(f); |
1187 | } | 1187 | } |
1188 | 1188 | ||
1189 | static public explicit operator LSLString(bool b) | ||
1190 | { | ||
1191 | if (b) | ||
1192 | return new LSLString("1"); | ||
1193 | else | ||
1194 | return new LSLString("0"); | ||
1195 | } | ||
1196 | |||
1189 | public static implicit operator Vector3(LSLString s) | 1197 | public static implicit operator Vector3(LSLString s) |
1190 | { | 1198 | { |
1191 | return new Vector3(s.m_string); | 1199 | return new Vector3(s.m_string); |
@@ -1303,6 +1311,14 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1303 | return new LSLInteger(f.value); | 1311 | return new LSLInteger(f.value); |
1304 | } | 1312 | } |
1305 | 1313 | ||
1314 | static public implicit operator LSLInteger(bool b) | ||
1315 | { | ||
1316 | if (b) | ||
1317 | return new LSLInteger(1); | ||
1318 | else | ||
1319 | return new LSLInteger(0); | ||
1320 | } | ||
1321 | |||
1306 | static public bool operator ==(LSLInteger i1, LSLInteger i2) | 1322 | static public bool operator ==(LSLInteger i1, LSLInteger i2) |
1307 | { | 1323 | { |
1308 | bool ret = i1.value == i2.value; | 1324 | bool ret = i1.value == i2.value; |
@@ -1481,6 +1497,14 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
1481 | return new LSLFloat(d); | 1497 | return new LSLFloat(d); |
1482 | } | 1498 | } |
1483 | 1499 | ||
1500 | static public implicit operator LSLFloat(bool b) | ||
1501 | { | ||
1502 | if (b) | ||
1503 | return new LSLFloat(1.0); | ||
1504 | else | ||
1505 | return new LSLFloat(0.0); | ||
1506 | } | ||
1507 | |||
1484 | static public bool operator ==(LSLFloat f1, LSLFloat f2) | 1508 | static public bool operator ==(LSLFloat f1, LSLFloat f2) |
1485 | { | 1509 | { |
1486 | return f1.value == f2.value; | 1510 | return f1.value == f2.value; |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index f02e970..fd9e1aa 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | |||
@@ -416,8 +416,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
416 | public const int OBJECT_CREATOR = 8; | 416 | public const int OBJECT_CREATOR = 8; |
417 | 417 | ||
418 | // Can not be public const? | 418 | // Can not be public const? |
419 | public vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0); | 419 | public static readonly vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0); |
420 | public rotation ZERO_ROTATION = new rotation(0.0, 0, 0.0, 1.0); | 420 | public static readonly rotation ZERO_ROTATION = new rotation(0.0, 0, 0.0, 1.0); |
421 | 421 | ||
422 | } | 422 | } |
423 | } | 423 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 25f6957..d15aa81 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | |||
@@ -1186,6 +1186,14 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
1186 | return new LSLString(f); | 1186 | return new LSLString(f); |
1187 | } | 1187 | } |
1188 | 1188 | ||
1189 | static public explicit operator LSLString(bool b) | ||
1190 | { | ||
1191 | if (b) | ||
1192 | return new LSLString("1"); | ||
1193 | else | ||
1194 | return new LSLString("0"); | ||
1195 | } | ||
1196 | |||
1189 | public static implicit operator Vector3(LSLString s) | 1197 | public static implicit operator Vector3(LSLString s) |
1190 | { | 1198 | { |
1191 | return new Vector3(s.m_string); | 1199 | return new Vector3(s.m_string); |
@@ -1303,6 +1311,14 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
1303 | return new LSLInteger(f.value); | 1311 | return new LSLInteger(f.value); |
1304 | } | 1312 | } |
1305 | 1313 | ||
1314 | static public implicit operator LSLInteger(bool b) | ||
1315 | { | ||
1316 | if (b) | ||
1317 | return new LSLInteger(1); | ||
1318 | else | ||
1319 | return new LSLInteger(0); | ||
1320 | } | ||
1321 | |||
1306 | static public bool operator ==(LSLInteger i1, LSLInteger i2) | 1322 | static public bool operator ==(LSLInteger i1, LSLInteger i2) |
1307 | { | 1323 | { |
1308 | bool ret = i1.value == i2.value; | 1324 | bool ret = i1.value == i2.value; |
@@ -1481,6 +1497,14 @@ namespace OpenSim.Region.ScriptEngine.Shared | |||
1481 | return new LSLFloat(d); | 1497 | return new LSLFloat(d); |
1482 | } | 1498 | } |
1483 | 1499 | ||
1500 | static public implicit operator LSLFloat(bool b) | ||
1501 | { | ||
1502 | if (b) | ||
1503 | return new LSLFloat(1.0); | ||
1504 | else | ||
1505 | return new LSLFloat(0.0); | ||
1506 | } | ||
1507 | |||
1484 | static public bool operator ==(LSLFloat f1, LSLFloat f2) | 1508 | static public bool operator ==(LSLFloat f1, LSLFloat f2) |
1485 | { | 1509 | { |
1486 | return f1.value == f2.value; | 1510 | return f1.value == f2.value; |
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs index 58ca8dd..d89bb87 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLFloat.cs | |||
@@ -558,5 +558,26 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests | |||
558 | } | 558 | } |
559 | } | 559 | } |
560 | } | 560 | } |
561 | |||
562 | /// <summary> | ||
563 | /// Tests boolean correctly cast implicitly to LSLFloat. | ||
564 | /// </summary> | ||
565 | [Test] | ||
566 | public void TestImplicitCastBooleanToLSLFloat() | ||
567 | { | ||
568 | LSL_Types.LSLFloat testFloat; | ||
569 | |||
570 | testFloat = (1 == 0); | ||
571 | Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); | ||
572 | |||
573 | testFloat = (1 == 1); | ||
574 | Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); | ||
575 | |||
576 | testFloat = false; | ||
577 | Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); | ||
578 | |||
579 | testFloat = true; | ||
580 | Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); | ||
581 | } | ||
561 | } | 582 | } |
562 | } | 583 | } |
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs index 3f01d09..d2839db 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLInteger.cs | |||
@@ -108,5 +108,26 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests | |||
108 | Assert.AreEqual(testInteger.value, number.Value); | 108 | Assert.AreEqual(testInteger.value, number.Value); |
109 | } | 109 | } |
110 | } | 110 | } |
111 | |||
112 | /// <summary> | ||
113 | /// Tests boolean correctly cast implicitly to LSLInteger. | ||
114 | /// </summary> | ||
115 | [Test] | ||
116 | public void TestImplicitCastBooleanToLSLInteger() | ||
117 | { | ||
118 | LSL_Types.LSLInteger testInteger; | ||
119 | |||
120 | testInteger = (1 == 0); | ||
121 | Assert.AreEqual(0, testInteger.value); | ||
122 | |||
123 | testInteger = (1 == 1); | ||
124 | Assert.AreEqual(1, testInteger.value); | ||
125 | |||
126 | testInteger = false; | ||
127 | Assert.AreEqual(0, testInteger.value); | ||
128 | |||
129 | testInteger = true; | ||
130 | Assert.AreEqual(1, testInteger.value); | ||
131 | } | ||
111 | } | 132 | } |
112 | } | 133 | } |
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs index 5d4424b..3aa52cb 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Common/LSL_TypesTestLSLString.cs | |||
@@ -111,5 +111,26 @@ namespace OpenSim.Region.ScriptEngine.Common.Tests | |||
111 | Assert.AreEqual(expectedQuaternion, stringQuaternion); | 111 | Assert.AreEqual(expectedQuaternion, stringQuaternion); |
112 | Assert.AreEqual(expectedQuaternion, LSLStringQuaternion); | 112 | Assert.AreEqual(expectedQuaternion, LSLStringQuaternion); |
113 | } | 113 | } |
114 | |||
115 | /// <summary> | ||
116 | /// Tests boolean correctly cast explicitly to LSLString. | ||
117 | /// </summary> | ||
118 | [Test] | ||
119 | public void TestImplicitCastBooleanToLSLFloat() | ||
120 | { | ||
121 | LSL_Types.LSLString testString; | ||
122 | |||
123 | testString = (LSL_Types.LSLString) (1 == 0); | ||
124 | Assert.AreEqual("0", testString.m_string); | ||
125 | |||
126 | testString = (LSL_Types.LSLString) (1 == 1); | ||
127 | Assert.AreEqual("1", testString.m_string); | ||
128 | |||
129 | testString = (LSL_Types.LSLString) false; | ||
130 | Assert.AreEqual("0", testString.m_string); | ||
131 | |||
132 | testString = (LSL_Types.LSLString) true; | ||
133 | Assert.AreEqual("1", testString.m_string); | ||
134 | } | ||
114 | } | 135 | } |
115 | } | 136 | } |
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs index d55f0e3..c021963 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs | |||
@@ -558,5 +558,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
558 | } | 558 | } |
559 | } | 559 | } |
560 | } | 560 | } |
561 | |||
562 | /// <summary> | ||
563 | /// Tests boolean correctly cast implicitly to LSLFloat. | ||
564 | /// </summary> | ||
565 | [Test] | ||
566 | public void TestImplicitCastBooleanToLSLFloat() | ||
567 | { | ||
568 | LSL_Types.LSLFloat testFloat; | ||
569 | |||
570 | testFloat = (1 == 0); | ||
571 | Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); | ||
572 | |||
573 | testFloat = (1 == 1); | ||
574 | Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); | ||
575 | |||
576 | testFloat = false; | ||
577 | Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); | ||
578 | |||
579 | testFloat = true; | ||
580 | Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); | ||
581 | } | ||
561 | } | 582 | } |
562 | } | 583 | } |
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs index d158084..f826c00 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs | |||
@@ -108,5 +108,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
108 | Assert.AreEqual(testInteger.value, number.Value); | 108 | Assert.AreEqual(testInteger.value, number.Value); |
109 | } | 109 | } |
110 | } | 110 | } |
111 | |||
112 | /// <summary> | ||
113 | /// Tests boolean correctly cast implicitly to LSLInteger. | ||
114 | /// </summary> | ||
115 | [Test] | ||
116 | public void TestImplicitCastBooleanToLSLInteger() | ||
117 | { | ||
118 | LSL_Types.LSLInteger testInteger; | ||
119 | |||
120 | testInteger = (1 == 0); | ||
121 | Assert.AreEqual(0, testInteger.value); | ||
122 | |||
123 | testInteger = (1 == 1); | ||
124 | Assert.AreEqual(1, testInteger.value); | ||
125 | |||
126 | testInteger = false; | ||
127 | Assert.AreEqual(0, testInteger.value); | ||
128 | |||
129 | testInteger = true; | ||
130 | Assert.AreEqual(1, testInteger.value); | ||
131 | } | ||
111 | } | 132 | } |
112 | } | 133 | } |
diff --git a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs index 8fcb385..49e5023 100644 --- a/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs +++ b/OpenSim/Tests/OpenSim/Region/ScriptEngine/Shared/LSL_TypesTestLSLString.cs | |||
@@ -111,5 +111,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
111 | Assert.AreEqual(expectedQuaternion, stringQuaternion); | 111 | Assert.AreEqual(expectedQuaternion, stringQuaternion); |
112 | Assert.AreEqual(expectedQuaternion, LSLStringQuaternion); | 112 | Assert.AreEqual(expectedQuaternion, LSLStringQuaternion); |
113 | } | 113 | } |
114 | |||
115 | /// <summary> | ||
116 | /// Tests boolean correctly cast explicitly to LSLString. | ||
117 | /// </summary> | ||
118 | [Test] | ||
119 | public void TestImplicitCastBooleanToLSLFloat() | ||
120 | { | ||
121 | LSL_Types.LSLString testString; | ||
122 | |||
123 | testString = (LSL_Types.LSLString) (1 == 0); | ||
124 | Assert.AreEqual("0", testString.m_string); | ||
125 | |||
126 | testString = (LSL_Types.LSLString) (1 == 1); | ||
127 | Assert.AreEqual("1", testString.m_string); | ||
128 | |||
129 | testString = (LSL_Types.LSLString) false; | ||
130 | Assert.AreEqual("0", testString.m_string); | ||
131 | |||
132 | testString = (LSL_Types.LSLString) true; | ||
133 | Assert.AreEqual("1", testString.m_string); | ||
134 | } | ||
114 | } | 135 | } |
115 | } | 136 | } |