]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/nasal-props.cxx
Remove hard-coded values wherever possible;
[flightgear.git] / src / Scripting / nasal-props.cxx
index 9f309903a11b7401a2b7992a49926bd53da9ab89..15a3016f3f31c9f1669625100132fe543d6c053a 100644 (file)
@@ -103,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();
@@ -128,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();
@@ -169,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_GENERAL, SG_ALERT, "Nasal getValue: property " << (*node)->getPath() << " is NaN");
+          return naNil();
+        }
+        
+        return naNum(dv);
+    }
+    
     case props::STRING:
     case props::UNSPECIFIED:
         return NASTR((*node)->getStringValue());
@@ -217,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);
 }
@@ -250,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));
 }