# include "config.h"
#endif
+#include <cstring>
+
+#include <simgear/math/SGMath.hxx>
#include <simgear/nasal/nasal.h>
#include <simgear/props/props.hxx>
#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.
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();
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();
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());
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);
}
{
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));
}