]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/nasal-props.cxx
#545: Fix ATC chatter sound settings being ignored
[flightgear.git] / src / Scripting / nasal-props.cxx
index 83f90ab0faf2ed67003d058415cb99e51248b0f8..0233b69ddada6eb8a4ee02a4168f82cf904105ee 100644 (file)
@@ -3,6 +3,9 @@
 #  include "config.h"
 #endif
 
+#include <cstring>
+
+#include <simgear/math/SGMath.hxx>
 #include <simgear/nasal/nasal.h>
 #include <simgear/props/props.hxx>
 
@@ -10,6 +13,8 @@
 
 #include "NasalSys.hxx"
 
+using namespace std;
+
 // Implementation of a Nasal wrapper for the SGPropertyNode class,
 // using the Nasal "ghost" (er... Garbage collection Handle for
 // OutSide Thingy) facility.
@@ -73,6 +78,7 @@ static naRef f_getType(naContext c, naRef me, int argc, naRef* args)
     case props::UNSPECIFIED: t = "UNSPECIFIED"; break;
     case props::VEC3D:  t = "VEC3D";  break;
     case props::VEC4D:  t = "VEC4D";  break;
+    case props::EXTENDED: t = "EXTENDED";  break; // shouldn't happen
     }
     return NASTR(t);
 }
@@ -97,6 +103,7 @@ static naRef f_getAttribute(naContext c, naRef me, int argc, naRef* args)
     else if(!strcmp(a, "trace-read"))  attr = SGPropertyNode::TRACE_READ;
     else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE;
     else if(!strcmp(a, "userarchive")) attr = SGPropertyNode::USERARCHIVE;
+    else if(!strcmp(a, "preserve"))    attr = SGPropertyNode::PRESERVE;
     else {
         naRuntimeError(c, "props.getAttribute() with invalid attribute");
         return naNil();
@@ -122,6 +129,7 @@ static naRef f_setAttribute(naContext c, naRef me, int argc, naRef* args)
     else if(!strcmp(a, "trace-read"))  attr = SGPropertyNode::TRACE_READ;
     else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE;
     else if(!strcmp(a, "userarchive")) attr = SGPropertyNode::USERARCHIVE;
+    else if(!strcmp(a, "preserve"))    attr = SGPropertyNode::PRESERVE;
     else {
         naRuntimeError(c, "props.setAttribute() with invalid attribute");
         return naNil();
@@ -146,7 +154,7 @@ static naRef f_getIndex(naContext c, naRef me, int argc, naRef* args)
 template<typename T>
 naRef makeVectorFromVec(naContext c, const T& vec)
 {
-    const unsigned num_components
+    const int num_components
         = sizeof(vec.data()) / sizeof(typename T::value_type);
     naRef vector = naNewVector(c);
     naVec_setsize(vector, num_components);
@@ -163,7 +171,16 @@ static naRef f_getValue(naContext c, naRef me, int argc, naRef* args)
     case props::BOOL:   case props::INT:
     case props::LONG:   case props::FLOAT:
     case props::DOUBLE:
-        return naNum((*node)->getDoubleValue());
+    {
+        double dv = (*node)->getDoubleValue();
+        if (osg::isNaN(dv)) {
+          SG_LOG(SG_NASAL, SG_ALERT, "Nasal getValue: property " << (*node)->getPath() << " is NaN");
+          return naNil();
+        }
+        
+        return naNum(dv);
+    }
+    
     case props::STRING:
     case props::UNSPECIFIED:
         return NASTR((*node)->getStringValue());
@@ -180,7 +197,7 @@ template<typename T>
 T makeVecFromVector(naRef vector)
 {
     T vec;
-    const unsigned num_components
+    const int num_components
         = sizeof(vec.data()) / sizeof(typename T::value_type);
     int size = naVec_size(vector);
 
@@ -211,7 +228,13 @@ static naRef f_setValue(naContext c, naRef me, int argc, naRef* args)
         naRef n = naNumValue(val);
         if(naIsNil(n))
             naRuntimeError(c, "props.setValue() with non-number");
-        result = (*node)->setDoubleValue(naNumValue(val).num);
+            
+        double d = naNumValue(val).num;
+        if (osg::isNaN(d)) {
+          naRuntimeError(c, "props.setValue() passed a NaN");
+        }
+        
+        result = (*node)->setDoubleValue(d);
     }
     return naNum(result);
 }
@@ -244,8 +267,13 @@ static naRef f_setDoubleValue(naContext c, naRef me, int argc, naRef* args)
 {
     NODEARG();
     naRef r = naNumValue(naVec_get(argv, 0));
-    if(naIsNil(r))
+    if (naIsNil(r))
         naRuntimeError(c, "props.setDoubleValue() with non-number");
+        
+    if (osg::isNaN(r.num)) {
+      naRuntimeError(c, "props.setDoubleValue() passed a NaN");
+    }
+        
     return naNum((*node)->setDoubleValue(r.num));
 }