]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/nasal-props.cxx
Merge branch 'maint2' into next
[flightgear.git] / src / Scripting / nasal-props.cxx
index 77c74a830b3b2042c77981cd943c2ee4f526f8a1..123af75391127d0eddf19062d928d2a4548309aa 100644 (file)
@@ -26,7 +26,7 @@ static void propNodeGhostDestroy(void* ghost)
     delete prop;
 }
 
-naGhostType PropNodeGhostType = { propNodeGhostDestroy };
+naGhostType PropNodeGhostType = { propNodeGhostDestroy, "prop" };
 
 static naRef propNodeGhostCreate(naContext c, SGPropertyNode* n)
 {
@@ -77,16 +77,19 @@ static naRef f_getType(naContext c, naRef me, int argc, naRef* args)
 static naRef f_getAttribute(naContext c, naRef me, int argc, naRef* args)
 {
     NODEARG();
-    if(naVec_size(argv) == 0) return naNum((*node)->getAttributes());
+    if(naVec_size(argv) == 0) return naNum(unsigned((*node)->getAttributes()));
     naRef val = naVec_get(argv, 0);
     char *a = naStr_data(val);
     SGPropertyNode::Attribute attr;
     if(!a) a = "";
-    if(!strcmp(a, "children"))         return naNum((*node)->nChildren());
+    if(!strcmp(a, "last")) return naNum(SGPropertyNode::LAST_USED_ATTRIBUTE);
+    else if(!strcmp(a, "children"))    return naNum((*node)->nChildren());
+    else if(!strcmp(a, "listeners"))   return naNum((*node)->nListeners());
+    else if(!strcmp(a, "references"))  return naNum(node->getNumRefs());
     else if(!strcmp(a, "tied"))        return naNum((*node)->isTied());
     else if(!strcmp(a, "alias"))       return naNum((*node)->isAlias());
-    else if(!strcmp(a, "read"))        attr = SGPropertyNode::READ;
-    else if(!strcmp(a, "write"))       attr = SGPropertyNode::WRITE;
+    else if(!strcmp(a, "readable"))    attr = SGPropertyNode::READ;
+    else if(!strcmp(a, "writable"))    attr = SGPropertyNode::WRITE;
     else if(!strcmp(a, "archive"))     attr = SGPropertyNode::ARCHIVE;
     else if(!strcmp(a, "trace-read"))  attr = SGPropertyNode::TRACE_READ;
     else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE;
@@ -110,8 +113,8 @@ static naRef f_setAttribute(naContext c, naRef me, int argc, naRef* args)
     SGPropertyNode::Attribute attr;
     char *a = naStr_data(val);
     if(!a) a = "";
-    if(!strcmp(a, "read"))             attr = SGPropertyNode::READ;
-    else if(!strcmp(a, "write"))       attr = SGPropertyNode::WRITE;
+    if(!strcmp(a, "readable"))         attr = SGPropertyNode::READ;
+    else if(!strcmp(a, "writable"))    attr = SGPropertyNode::WRITE;
     else if(!strcmp(a, "archive"))     attr = SGPropertyNode::ARCHIVE;
     else if(!strcmp(a, "trace-read"))  attr = SGPropertyNode::TRACE_READ;
     else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE;
@@ -264,12 +267,13 @@ 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();
+    SGPropertyNode_ptr n = 0;
     try {
-        (*node)->removeChild(naStr_data(child), (int)index.num, false);
+        n = (*node)->removeChild(naStr_data(child), (int)index.num, false);
     } catch (const string& err) {
         naRuntimeError(c, (char *)err.c_str());
     }
-    return naNil();
+    return propNodeGhostCreate(c, n);
 }
 
 static naRef f_removeChildren(naContext c, naRef me, int argc, naRef* args)
@@ -297,6 +301,34 @@ static naRef f_removeChildren(naContext c, naRef me, int argc, naRef* args)
     return result;
 }
 
+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 = *(SGPropertyNode_ptr*)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));
+}
+
+static naRef f_unalias(naContext c, naRef me, int argc, naRef* args)
+{
+    NODEARG();
+    return naNum((*node)->unalias());
+}
+
+static naRef f_getAliasTarget(naContext c, naRef me, int argc, naRef* args)
+{
+    NODEARG();
+    return propNodeGhostCreate(c, (*node)->getAliasTarget());
+}
+
 static naRef f_getNode(naContext c, naRef me, int argc, naRef* args)
 {
     NODEARG();
@@ -325,7 +357,7 @@ static naRef f_globals(naContext c, naRef me, int argc, naRef* args)
 
 static struct {
     naCFunction func;
-    char* name;
+    const char* name;
 } propfuncs[] = {
     { f_getType, "_getType" },
     { f_getAttribute, "_getAttribute" },
@@ -342,6 +374,9 @@ static struct {
     { f_getChildren, "_getChildren" },
     { f_removeChild, "_removeChild" },
     { f_removeChildren, "_removeChildren" },
+    { f_alias, "_alias" },
+    { f_unalias, "_unalias" },
+    { f_getAliasTarget, "_getAliasTarget" },
     { f_getNode, "_getNode" },
     { f_new, "_new" },
     { f_globals, "_globals" },