From 57ec7a26cda361eeac9d7f010194cfe0dfa6c281 Mon Sep 17 00:00:00 2001 From: Mike Mazur Date: Thu, 31 Jul 2008 07:11:41 +0000 Subject: -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 --- .../DotNetEngine/Compiler/LSL/LSL_BaseClass.cs | 4 ++-- .../Common/BuiltIn_Commands_BaseClass.cs | 4 ++-- OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | 24 ++++++++++++++++++++++ .../Shared/Api/Runtime/LSL_Constants.cs | 4 ++-- OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 24 ++++++++++++++++++++++ .../ScriptEngine/Common/LSL_TypesTestLSLFloat.cs | 21 +++++++++++++++++++ .../ScriptEngine/Common/LSL_TypesTestLSLInteger.cs | 21 +++++++++++++++++++ .../ScriptEngine/Common/LSL_TypesTestLSLString.cs | 21 +++++++++++++++++++ .../ScriptEngine/Shared/LSL_TypesTestLSLFloat.cs | 21 +++++++++++++++++++ .../ScriptEngine/Shared/LSL_TypesTestLSLInteger.cs | 21 +++++++++++++++++++ .../ScriptEngine/Shared/LSL_TypesTestLSLString.cs | 21 +++++++++++++++++++ 11 files changed, 180 insertions(+), 6 deletions(-) (limited to 'OpenSim') 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 public const int PUBLIC_CHANNEL 0x00000000 // Can not be public const? - public vector ZERO_VECTOR = new vector(0, 0, 0); - public rotation ZERO_ROTATION = new rotation(0, 0, 0, 0); + public static readonly vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0); + public static readonly rotation ZERO_ROTATION = new rotation(0.0, 0.0, 0.0, 1.0); } } 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 public const int OBJECT_CREATOR = 8; // Can not be public const? - public vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0); - public rotation ZERO_ROTATION = new rotation(0.0, 0, 0.0, 1.0); + public static readonly vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0); + public static readonly rotation ZERO_ROTATION = new rotation(0.0, 0, 0.0, 1.0); } } 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 return new LSLString(f); } + static public explicit operator LSLString(bool b) + { + if (b) + return new LSLString("1"); + else + return new LSLString("0"); + } + public static implicit operator Vector3(LSLString s) { return new Vector3(s.m_string); @@ -1303,6 +1311,14 @@ namespace OpenSim.Region.ScriptEngine.Common return new LSLInteger(f.value); } + static public implicit operator LSLInteger(bool b) + { + if (b) + return new LSLInteger(1); + else + return new LSLInteger(0); + } + static public bool operator ==(LSLInteger i1, LSLInteger i2) { bool ret = i1.value == i2.value; @@ -1481,6 +1497,14 @@ namespace OpenSim.Region.ScriptEngine.Common return new LSLFloat(d); } + static public implicit operator LSLFloat(bool b) + { + if (b) + return new LSLFloat(1.0); + else + return new LSLFloat(0.0); + } + static public bool operator ==(LSLFloat f1, LSLFloat f2) { 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 public const int OBJECT_CREATOR = 8; // Can not be public const? - public vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0); - public rotation ZERO_ROTATION = new rotation(0.0, 0, 0.0, 1.0); + public static readonly vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0); + public static readonly rotation ZERO_ROTATION = new rotation(0.0, 0, 0.0, 1.0); } } 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 return new LSLString(f); } + static public explicit operator LSLString(bool b) + { + if (b) + return new LSLString("1"); + else + return new LSLString("0"); + } + public static implicit operator Vector3(LSLString s) { return new Vector3(s.m_string); @@ -1303,6 +1311,14 @@ namespace OpenSim.Region.ScriptEngine.Shared return new LSLInteger(f.value); } + static public implicit operator LSLInteger(bool b) + { + if (b) + return new LSLInteger(1); + else + return new LSLInteger(0); + } + static public bool operator ==(LSLInteger i1, LSLInteger i2) { bool ret = i1.value == i2.value; @@ -1481,6 +1497,14 @@ namespace OpenSim.Region.ScriptEngine.Shared return new LSLFloat(d); } + static public implicit operator LSLFloat(bool b) + { + if (b) + return new LSLFloat(1.0); + else + return new LSLFloat(0.0); + } + static public bool operator ==(LSLFloat f1, LSLFloat f2) { 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 } } } + + /// + /// Tests boolean correctly cast implicitly to LSLFloat. + /// + [Test] + public void TestImplicitCastBooleanToLSLFloat() + { + LSL_Types.LSLFloat testFloat; + + testFloat = (1 == 0); + Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); + + testFloat = (1 == 1); + Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); + + testFloat = false; + Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); + + testFloat = true; + Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); + } } } 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 Assert.AreEqual(testInteger.value, number.Value); } } + + /// + /// Tests boolean correctly cast implicitly to LSLInteger. + /// + [Test] + public void TestImplicitCastBooleanToLSLInteger() + { + LSL_Types.LSLInteger testInteger; + + testInteger = (1 == 0); + Assert.AreEqual(0, testInteger.value); + + testInteger = (1 == 1); + Assert.AreEqual(1, testInteger.value); + + testInteger = false; + Assert.AreEqual(0, testInteger.value); + + testInteger = true; + Assert.AreEqual(1, testInteger.value); + } } } 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 Assert.AreEqual(expectedQuaternion, stringQuaternion); Assert.AreEqual(expectedQuaternion, LSLStringQuaternion); } + + /// + /// Tests boolean correctly cast explicitly to LSLString. + /// + [Test] + public void TestImplicitCastBooleanToLSLFloat() + { + LSL_Types.LSLString testString; + + testString = (LSL_Types.LSLString) (1 == 0); + Assert.AreEqual("0", testString.m_string); + + testString = (LSL_Types.LSLString) (1 == 1); + Assert.AreEqual("1", testString.m_string); + + testString = (LSL_Types.LSLString) false; + Assert.AreEqual("0", testString.m_string); + + testString = (LSL_Types.LSLString) true; + Assert.AreEqual("1", testString.m_string); + } } } 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 } } } + + /// + /// Tests boolean correctly cast implicitly to LSLFloat. + /// + [Test] + public void TestImplicitCastBooleanToLSLFloat() + { + LSL_Types.LSLFloat testFloat; + + testFloat = (1 == 0); + Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); + + testFloat = (1 == 1); + Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); + + testFloat = false; + Assert.That(testFloat.value, new DoubleToleranceConstraint(0.0, _lowPrecisionTolerance)); + + testFloat = true; + Assert.That(testFloat.value, new DoubleToleranceConstraint(1.0, _lowPrecisionTolerance)); + } } } 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 Assert.AreEqual(testInteger.value, number.Value); } } + + /// + /// Tests boolean correctly cast implicitly to LSLInteger. + /// + [Test] + public void TestImplicitCastBooleanToLSLInteger() + { + LSL_Types.LSLInteger testInteger; + + testInteger = (1 == 0); + Assert.AreEqual(0, testInteger.value); + + testInteger = (1 == 1); + Assert.AreEqual(1, testInteger.value); + + testInteger = false; + Assert.AreEqual(0, testInteger.value); + + testInteger = true; + Assert.AreEqual(1, testInteger.value); + } } } 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 Assert.AreEqual(expectedQuaternion, stringQuaternion); Assert.AreEqual(expectedQuaternion, LSLStringQuaternion); } + + /// + /// Tests boolean correctly cast explicitly to LSLString. + /// + [Test] + public void TestImplicitCastBooleanToLSLFloat() + { + LSL_Types.LSLString testString; + + testString = (LSL_Types.LSLString) (1 == 0); + Assert.AreEqual("0", testString.m_string); + + testString = (LSL_Types.LSLString) (1 == 1); + Assert.AreEqual("1", testString.m_string); + + testString = (LSL_Types.LSLString) false; + Assert.AreEqual("0", testString.m_string); + + testString = (LSL_Types.LSLString) true; + Assert.AreEqual("1", testString.m_string); + } } } -- cgit v1.1