+
+// Remove all children with specified name. Returns a vector of all the nodes
+// removed as ghosts.
+// Forms:
+// props.Node.removeChildren(string relative_path);
+// props.Node.removeChildren(); #remove all children
+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();
+ try {
+ vector<SGPropertyNode_ptr> children
+ = node->removeChildren(naStr_data(name));
+ for(unsigned int i=0; i<children.size(); i++)
+ naVec_append(result, propNodeGhostCreate(c, children[i]));
+ } catch (const string& err) {
+ naRuntimeError(c, (char *)err.c_str());
+ return naNil();
+ }
+ }
+ return result;
+}
+
+// Remove all children of a property node.
+// Forms:
+// props.Node.removeAllChildren();
+static naRef f_removeAllChildren(naContext c, naRef me, int argc, naRef* args)
+{
+ NODENOARG();
+ node->removeAllChildren();
+ return propNodeGhostCreate(c, node);
+}
+
+// Alias this property to another one; returns 1 on success or 0 on failure
+// (only applicable to tied properties).
+// Forms:
+// props.Node.alias(string global_path);
+// props.Node.alias(prop_ghost node);
+// props.Node.alias(props.Node node); #added by props.nas
+static naRef f_alias(naContext c, naRef me, int argc, naRef* args)
+{
+ NODEARG();
+ SGPropertyNode* al;
+ naRef prop = naVec_get(argv, 0);
+ try {
+ if(naIsString(prop)) al = globals->get_props()->getNode(naStr_data(prop), true);
+ else if(naIsGhost(prop)) al = static_cast<SGPropertyNode*>(naGhost_ptr(prop));
+ else throw string("props.alias() with bad argument");
+ } catch (const string& err) {
+ naRuntimeError(c, (char *)err.c_str());
+ return naNil();
+ }
+ return naNum(node->alias(al));
+}
+
+
+// Un-alias this property. Returns 1 on success or 0 on failure (only
+// applicable to tied properties).
+// Forms:
+// props.Node.unalias();
+static naRef f_unalias(naContext c, naRef me, int argc, naRef* args)
+{
+ NODENOARG();
+ return naNum(node->unalias());
+}
+
+
+// Get the alias of this node as a ghost.
+// Forms:
+// props.Node.getAliasTarget();
+static naRef f_getAliasTarget(naContext c, naRef me, int argc, naRef* args)
+{
+ NODENOARG();
+ return propNodeGhostCreate(c, node->getAliasTarget());
+}
+
+
+// Get a relative node. Returns nil if it does not exist and create is false,
+// or a ghost object otherwise (wrapped into a props.Node object by props.nas).
+// Forms:
+// props.Node.getNode(string relative_path,
+// bool create=false);