From cad193a1c4a94dafa35d6227a98a2b58a244c55b Mon Sep 17 00:00:00 2001 From: mfranz Date: Sun, 23 Oct 2005 16:10:32 +0000 Subject: [PATCH] add support for removeChildren(): takes one name as optional argument and removes all children with this name; if no name is given, removes all children (OK'ed by Andy) --- src/Scripting/nasal-props.cxx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Scripting/nasal-props.cxx b/src/Scripting/nasal-props.cxx index 2e530c9bd..f68850916 100644 --- a/src/Scripting/nasal-props.cxx +++ b/src/Scripting/nasal-props.cxx @@ -190,6 +190,26 @@ static naRef f_removeChild(naContext c, naRef me, int argc, naRef* args) 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 children + = (*node)->removeChildren(naStr_data(name)); + for(unsigned int i=0; i