+
+// Append a named child at the first unused index...
+// Forms:
+// props.Node.addChild(string name,
+// int min_index=0,
+// bool append=true);
+static naRef f_addChild(naContext c, naRef me, int argc, naRef* args)
+{
+ NODEARG();
+ naRef child = naVec_get(argv, 0);
+ if(!naIsString(child)) return naNil();
+ naRef ref_min_index = naNumValue(naVec_get(argv, 1));
+ naRef ref_append = naVec_get(argv, 2);
+ SGPropertyNode* n;
+ try
+ {
+ int min_index = 0;
+ if(!naIsNil(ref_min_index))
+ min_index = ref_min_index.num;
+
+ bool append = true;
+ if(!naIsNil(ref_append))
+ append = naTrue(ref_append) != 0;
+
+ n = node->addChild(naStr_data(child), min_index, append);
+ }
+ catch (const string& err)
+ {
+ naRuntimeError(c, (char *)err.c_str());
+ return naNil();
+ }
+
+ return propNodeGhostCreate(c, n);
+}
+
+static naRef f_addChildren(naContext c, naRef me, int argc, naRef* args)
+{
+ NODEARG();
+ naRef child = naVec_get(argv, 0);
+ if(!naIsString(child)) return naNil();
+ naRef ref_count = naNumValue(naVec_get(argv, 1));
+ naRef ref_min_index = naNumValue(naVec_get(argv, 2));
+ naRef ref_append = naVec_get(argv, 3);
+ try
+ {
+ size_t count = 0;
+ if( !naIsNum(ref_count) )
+ throw string("props.addChildren() missing number of children");
+ count = ref_count.num;
+
+ int min_index = 0;
+ if(!naIsNil(ref_min_index))
+ min_index = ref_min_index.num;
+
+ bool append = true;
+ if(!naIsNil(ref_append))
+ append = naTrue(ref_append) != 0;
+
+ const simgear::PropertyList& nodes =
+ node->addChildren(naStr_data(child), count, min_index, append);
+
+ naRef result = naNewVector(c);
+ for( size_t i = 0; i < nodes.size(); ++i )
+ naVec_append(result, propNodeGhostCreate(c, nodes[i]));
+ return result;
+ }
+ catch (const string& err)
+ {
+ naRuntimeError(c, (char *)err.c_str());
+ }
+
+ return naNil();
+}
+
+
+// Remove a child by name and index. Returns it as a ghost.
+// Forms:
+// props.Node.removeChild(string relative_path,
+// int index);