From 3a4b54adaa25de61aee04f71a88de86535b35670 Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Thu, 5 Jun 2008 13:54:20 +0000 Subject: Mantis#1451. Thank you kindly, Mikem for a patch that addresses: LSL scripts in which a float type is cast to a string or a string type is cast to a float do not compile. When the script is translated from LSL to C#, the LSL float type is translated into double. There is no string <-> double cast in C#, so compilation fails. There is a LSLFloat type, however it seems unfinished and is not used. I am attaching a patch that implements the LSLFloat type. I have also added two methods to the LSLString type to facilitate float <-> string casts. --- OpenSim/Region/ScriptEngine/Common/LSL_Types.cs | 73 +++++++++++++++++++--- .../DotNetEngine/Compiler/LSL/LSL2CSConverter.cs | 2 +- 2 files changed, 65 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs index c8c51f8..f8650a0 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs @@ -1088,6 +1088,12 @@ namespace OpenSim.Region.ScriptEngine.Common m_string=s; } + public LSLString(LSLFloat f) + { + string s=String.Format("{0:0.000000}", f.value); + m_string=s; + } + #endregion #region Operators @@ -1150,6 +1156,11 @@ namespace OpenSim.Region.ScriptEngine.Common return new LSLString(d); } + public static explicit operator LSLString(LSLFloat f) + { + return new LSLString(f); + } + public static implicit operator Vector3(LSLString s) { return new Vector3(s.m_string); @@ -1202,6 +1213,8 @@ namespace OpenSim.Region.ScriptEngine.Common #endregion + #region Operators + static public implicit operator int(LSLInteger i) { return i.value; @@ -1290,6 +1303,8 @@ namespace OpenSim.Region.ScriptEngine.Common return i.value == 0; } + #endregion + #region Overriders public override string ToString() @@ -1306,6 +1321,7 @@ namespace OpenSim.Region.ScriptEngine.Common public double value; #region Constructors + public LSLFloat(int i) { this.value = (double)i; @@ -1320,20 +1336,19 @@ namespace OpenSim.Region.ScriptEngine.Common #region Operators - static public implicit operator Double(LSLFloat f) + static public implicit operator int(LSLFloat f) { - return f.value; + return (int)f.value; } - //static public implicit operator System.Int32(LSLFloat f) - //{ - // return (int)f.value; - //} - + static public implicit operator uint(LSLFloat f) + { + return (uint) Math.Abs(f.value); + } static public implicit operator Boolean(LSLFloat f) { - if (f.value == 0) + if (f.value == 0.0) { return false; } @@ -1348,17 +1363,57 @@ namespace OpenSim.Region.ScriptEngine.Common return new LSLFloat(i); } + static public implicit operator LSLFloat(string s) + { + return new LSLFloat(double.Parse(s)); + } + static public implicit operator LSLFloat(double d) { return new LSLFloat(d); } + + static public bool operator ==(LSLFloat f1, LSLFloat f2) + { + return f1.value == f2.value; + } + + static public bool operator !=(LSLFloat f1, LSLFloat f2) + { + return f1.value != f2.value; + } + + static public LSLFloat operator ++(LSLFloat f) + { + f.value++; + return f; + } + + static public LSLFloat operator --(LSLFloat f) + { + f.value--; + return f; + } + + static public implicit operator System.Double(LSLFloat f) + { + return f.value; + } + + //static public implicit operator System.Int32(LSLFloat f) + //{ + // return (int)f.value; + //} + #endregion #region Overriders + public override string ToString() { - return this.value.ToString(); + return String.Format("{0:0.000000}", this.value); } + #endregion } } diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs index 583bb93..db73f6b 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs @@ -52,7 +52,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL // Only the types we need to convert dataTypes.Add("void", "void"); dataTypes.Add("integer", "LSL_Types.LSLInteger"); - dataTypes.Add("float", "double"); + dataTypes.Add("float", "LSL_Types.LSLFloat"); dataTypes.Add("string", "LSL_Types.LSLString"); dataTypes.Add("key", "LSL_Types.LSLString"); dataTypes.Add("vector", "LSL_Types.Vector3"); -- cgit v1.1