]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/nasal-props.cxx
Add an srand() function to nasal (hooked into sg_srandom_time()).
[flightgear.git] / src / Scripting / nasal-props.cxx
index 2e530c9bda364e1bd2cee26bd1dbef0da4da65d1..63ec50218f34d5b8015be0f282033761ee4bc41c 100644 (file)
@@ -186,10 +186,30 @@ static naRef f_removeChild(naContext c, naRef me, int argc, naRef* args)
     naRef child = naVec_get(argv, 0);
     naRef index = naVec_get(argv, 1);
     if(!naIsString(child) || !naIsNum(index)) return naNil();
-    (*node)->removeChild(naStr_data(child), (int)index.num);
+    (*node)->removeChild(naStr_data(child), (int)index.num, false);
     return naNil();
 }
 
+static naRef f_removeChildren(naContext c, naRef me, int argc, naRef* args)
+{
+    NODEARG();
+    naRef result = naNewVector(c);
+    if(naIsNil(argv) || naVec_size(argv) == 0) {
+        // Remove all children
+        for(int i = (*node)->nChildren() - 1; i >=0; i--)
+            naVec_append(result, propNodeGhostCreate(c, (*node)->removeChild(i)));
+    } else {
+        // Remove all children of a specified name
+        naRef name = naVec_get(argv, 0);
+        if(!naIsString(name)) return naNil();
+        vector<SGPropertyNode_ptr> children
+            = (*node)->removeChildren(naStr_data(name), false);
+        for(unsigned int i=0; i<children.size(); i++)
+            naVec_append(result, propNodeGhostCreate(c, children[i]));
+    }
+    return result;
+}
+
 static naRef f_getNode(naContext c, naRef me, int argc, naRef* args)
 {
     NODEARG();
@@ -226,6 +246,7 @@ static struct {
     { f_getChild, "_getChild" },
     { f_getChildren, "_getChildren" },
     { f_removeChild, "_removeChild" },
+    { f_removeChildren, "_removeChildren" },
     { f_getNode, "_getNode" },
     { f_new, "_new" },
     { f_globals, "_globals" },