]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/nasal-props.cxx
Boris Koenig:
[flightgear.git] / src / Scripting / nasal-props.cxx
index de0efca33fac241c29c8835dcc481b41663fb243..b53895953240da503a087f8f02106be18a2f2efa 100644 (file)
@@ -25,6 +25,7 @@ naGhostType PropNodeGhostType = { propNodeGhostDestroy };
 
 static naRef propNodeGhostCreate(naContext c, SGPropertyNode* n)
 {
+    if(!n) return naNil();
     SGPropertyNode_ptr* ghost = new SGPropertyNode_ptr(n);
     return naNewGhost(c, &PropNodeGhostType, ghost);
 }
@@ -110,7 +111,15 @@ static naRef f_setValue(naContext c, naRef args)
 static naRef f_setIntValue(naContext c, naRef args)
 {
     NODEARG();
-    int iv = (int)naNumValue(naVec_get(args, 0)).num;
+    // Original code:
+    //   int iv = (int)naNumValue(naVec_get(args, 0)).num;
+
+    // Junk to pacify the gcc-2.95.3 optimizer:
+    naRef tmp0 = naVec_get(args, 0);
+    naRef tmp1 = naNumValue(tmp0);
+    double tmp2 = tmp1.num;
+    int iv = (int)tmp2;
+
     (*node)->setIntValue(iv);
     return naNil();
 }
@@ -143,7 +152,13 @@ static naRef f_getChild(naContext c, naRef args)
     NODEARG();
     naRef child = naVec_get(args, 0);
     if(!naIsString(child)) return naNil();
-    SGPropertyNode* n = (*node)->getChild(naStr_data(child));
+    naRef idx = naNumValue(naVec_get(args, 1));
+    SGPropertyNode* n;
+    if(naIsNil(idx) || !naIsNum(idx)) {
+        n = (*node)->getChild(naStr_data(child));
+    } else {
+        n = (*node)->getChild(naStr_data(child), (int)idx.num);
+    }
     if(!n) return naNil();
     return propNodeGhostCreate(c, n);
 }
@@ -162,7 +177,7 @@ static naRef f_getChildren(naContext c, naRef args)
         if(!naIsString(name)) return naNil();
         vector<SGPropertyNode_ptr> children
             = (*node)->getChildren(naStr_data(name));
-        for(int i=0; i<children.size(); i++)
+        for(unsigned int i=0; i<children.size(); i++)
             naVec_append(result, propNodeGhostCreate(c, children[i]));
     }
     return result;