aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
authorCharles Krinke2008-07-16 14:30:22 +0000
committerCharles Krinke2008-07-16 14:30:22 +0000
commit0106f967161b2fa0dbf131a56e9c5498d1b16270 (patch)
tree62e0cbad5193521f7a2549bb782207306ca9e92c /OpenSim/Region/ScriptEngine
parentsquashing warnings critters (diff)
downloadopensim-SC_OLD-0106f967161b2fa0dbf131a56e9c5498d1b16270.zip
opensim-SC_OLD-0106f967161b2fa0dbf131a56e9c5498d1b16270.tar.gz
opensim-SC_OLD-0106f967161b2fa0dbf131a56e9c5498d1b16270.tar.bz2
opensim-SC_OLD-0106f967161b2fa0dbf131a56e9c5498d1b16270.tar.xz
Mantis#1755. Thank you kindly, Matth for a patch that solves:
When using math operators +,-,*,/ in an LSL script with an LSLFloat and an integer literal the wrong result is returned. This patch adds operators to the LSLFloat type to handle this case.
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/LSL_Types.cs71
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs68
2 files changed, 107 insertions, 32 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
index 3dfa711..c630c27 100644
--- a/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Common/LSL_Types.cs
@@ -1276,11 +1276,11 @@ namespace OpenSim.Region.ScriptEngine.Common
1276 return new LSLInteger(int.Parse(s)); 1276 return new LSLInteger(int.Parse(s));
1277 } 1277 }
1278 1278
1279 static public implicit operator LSLInteger(double d) 1279 static public implicit operator LSLInteger(uint u)
1280 { 1280 {
1281 return new LSLInteger(d); 1281 return new LSLInteger(u);
1282 } 1282 }
1283 1283
1284 static public bool operator ==(LSLInteger i1, LSLInteger i2) 1284 static public bool operator ==(LSLInteger i1, LSLInteger i2)
1285 { 1285 {
1286 bool ret = i1.value == i2.value; 1286 bool ret = i1.value == i2.value;
@@ -1312,6 +1312,31 @@ namespace OpenSim.Region.ScriptEngine.Common
1312 { 1312 {
1313 return new LSLInteger(i1.value / i2); 1313 return new LSLInteger(i1.value / i2);
1314 } 1314 }
1315
1316 static public LSLFloat operator +(LSLInteger i1, double f)
1317 {
1318 return new LSLFloat((double)i1.value + f);
1319 }
1320
1321 static public LSLFloat operator -(LSLInteger i1, double f)
1322 {
1323 return new LSLFloat((double)i1.value - f);
1324 }
1325
1326 static public LSLFloat operator *(LSLInteger i1, double f)
1327 {
1328 return new LSLFloat((double)i1.value * f);
1329 }
1330
1331 static public LSLFloat operator /(LSLInteger i1, double f)
1332 {
1333 return new LSLFloat((double)i1.value / f);
1334 }
1335
1336 static public LSLInteger operator -(LSLInteger i)
1337 {
1338 return new LSLInteger(-i.value);
1339 }
1315 1340
1316 public override bool Equals(Object o) 1341 public override bool Equals(Object o)
1317 { 1342 {
@@ -1392,16 +1417,6 @@ namespace OpenSim.Region.ScriptEngine.Common
1392 1417
1393 #region Operators 1418 #region Operators
1394 1419
1395 static public implicit operator int(LSLFloat f)
1396 {
1397 return (int)f.value;
1398 }
1399
1400 static public implicit operator uint(LSLFloat f)
1401 {
1402 return (uint) Math.Abs(f.value);
1403 }
1404
1405 static public implicit operator Boolean(LSLFloat f) 1420 static public implicit operator Boolean(LSLFloat f)
1406 { 1421 {
1407 if (f.value == 0.0) 1422 if (f.value == 0.0)
@@ -1450,17 +1465,37 @@ namespace OpenSim.Region.ScriptEngine.Common
1450 f.value--; 1465 f.value--;
1451 return f; 1466 return f;
1452 } 1467 }
1468
1469 static public LSLFloat operator +(LSLFloat f, int i)
1470 {
1471 return new LSLFloat(f.value + (double)i);
1472 }
1473
1474 static public LSLFloat operator -(LSLFloat f, int i)
1475 {
1476 return new LSLFloat(f.value - (double)i);
1477 }
1478
1479 static public LSLFloat operator *(LSLFloat f, int i)
1480 {
1481 return new LSLFloat(f.value * (double)i);
1482 }
1483
1484 static public LSLFloat operator /(LSLFloat f, int i)
1485 {
1486 return new LSLFloat(f.value / (double)i);
1487 }
1488
1489 static public LSLFloat operator -(LSLFloat f)
1490 {
1491 return new LSLFloat(-f.value);
1492 }
1453 1493
1454 static public implicit operator System.Double(LSLFloat f) 1494 static public implicit operator System.Double(LSLFloat f)
1455 { 1495 {
1456 return f.value; 1496 return f.value;
1457 } 1497 }
1458 1498
1459 //static public implicit operator System.Int32(LSLFloat f)
1460 //{
1461 // return (int)f.value;
1462 //}
1463
1464 #endregion 1499 #endregion
1465 1500
1466 #region Overriders 1501 #region Overriders
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 7ababb4..f71d584 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -1303,10 +1303,10 @@ namespace OpenSim.Region.ScriptEngine.Shared
1303 { 1303 {
1304 return new LSLInteger(int.Parse(s)); 1304 return new LSLInteger(int.Parse(s));
1305 } 1305 }
1306 1306
1307 static public implicit operator LSLInteger(double d) 1307 static public implicit operator LSLInteger(uint u)
1308 { 1308 {
1309 return new LSLInteger(d); 1309 return new LSLInteger(u);
1310 } 1310 }
1311 1311
1312 static public bool operator ==(LSLInteger i1, LSLInteger i2) 1312 static public bool operator ==(LSLInteger i1, LSLInteger i2)
@@ -1341,9 +1341,34 @@ namespace OpenSim.Region.ScriptEngine.Shared
1341 return new LSLInteger(i1.value / i2); 1341 return new LSLInteger(i1.value / i2);
1342 } 1342 }
1343 1343
1344 static public LSLFloat operator +(LSLInteger i1, double f)
1345 {
1346 return new LSLFloat((double)i1.value + f);
1347 }
1348
1349 static public LSLFloat operator -(LSLInteger i1, double f)
1350 {
1351 return new LSLFloat((double)i1.value - f);
1352 }
1353
1354 static public LSLFloat operator *(LSLInteger i1, double f)
1355 {
1356 return new LSLFloat((double)i1.value * f);
1357 }
1358
1359 static public LSLFloat operator /(LSLInteger i1, double f)
1360 {
1361 return new LSLFloat((double)i1.value / f);
1362 }
1363
1364 static public LSLInteger operator -(LSLInteger i)
1365 {
1366 return new LSLInteger(-i.value);
1367 }
1368
1344 static public LSLInteger operator &(LSLInteger i1, LSLInteger i2) 1369 static public LSLInteger operator &(LSLInteger i1, LSLInteger i2)
1345 { 1370 {
1346 int ret = i1.value & i2.value; 1371 int ret = i1.value & i2.value;
1347 return ret; 1372 return ret;
1348 } 1373 }
1349 1374
@@ -1447,16 +1472,6 @@ namespace OpenSim.Region.ScriptEngine.Shared
1447 1472
1448 #region Operators 1473 #region Operators
1449 1474
1450 static public implicit operator int(LSLFloat f)
1451 {
1452 return (int)f.value;
1453 }
1454
1455 static public implicit operator uint(LSLFloat f)
1456 {
1457 return (uint) Math.Abs(f.value);
1458 }
1459
1460 static public implicit operator Boolean(LSLFloat f) 1475 static public implicit operator Boolean(LSLFloat f)
1461 { 1476 {
1462 if (f.value == 0.0) 1477 if (f.value == 0.0)
@@ -1518,7 +1533,32 @@ namespace OpenSim.Region.ScriptEngine.Shared
1518 f.value--; 1533 f.value--;
1519 return f; 1534 return f;
1520 } 1535 }
1536
1537 static public LSLFloat operator +(LSLFloat f, int i)
1538 {
1539 return new LSLFloat(f.value + (double)i);
1540 }
1541
1542 static public LSLFloat operator -(LSLFloat f, int i)
1543 {
1544 return new LSLFloat(f.value - (double)i);
1545 }
1546
1547 static public LSLFloat operator *(LSLFloat f, int i)
1548 {
1549 return new LSLFloat(f.value * (double)i);
1550 }
1551
1552 static public LSLFloat operator /(LSLFloat f, int i)
1553 {
1554 return new LSLFloat(f.value / (double)i);
1555 }
1521 1556
1557 static public LSLFloat operator -(LSLFloat f)
1558 {
1559 return new LSLFloat(-f.value);
1560 }
1561
1522 static public implicit operator System.Double(LSLFloat f) 1562 static public implicit operator System.Double(LSLFloat f)
1523 { 1563 {
1524 return f.value; 1564 return f.value;