]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scripting/nasal-props.cxx
Modified Files:
[flightgear.git] / src / Scripting / nasal-props.cxx
index ea6548ade3f38d42c89458c57b3cfb110d87027e..0ff80e7649f65320234446954049c5e80066a229 100644 (file)
@@ -77,19 +77,23 @@ 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());
     naRef val = naVec_get(argv, 0);
     char *a = naStr_data(val);
     SGPropertyNode::Attribute attr;
     if(!a) a = "";
-    if(!strcmp(a, "read"))             attr = SGPropertyNode::READ;
+    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, "archive"))     attr = SGPropertyNode::ARCHIVE;
     else if(!strcmp(a, "trace-read"))  attr = SGPropertyNode::TRACE_READ;
     else if(!strcmp(a, "trace-write")) attr = SGPropertyNode::TRACE_WRITE;
     else if(!strcmp(a, "userarchive")) attr = SGPropertyNode::USERARCHIVE;
-    else if(!strcmp(a, "tied")) {
-        return naNum((*node)->isTied());
-    } else {
+    else {
         naRuntimeError(c, "props.getAttribute() with invalid attribute");
         return naNil();
     }
@@ -100,8 +104,13 @@ static naRef f_setAttribute(naContext c, naRef me, int argc, naRef* args)
 {
     NODEARG();
     naRef val = naVec_get(argv, 0);
-    char *a = naStr_data(val);
+    if(naVec_size(argv) == 1 && naIsNum(val)) {
+        naRef ret = naNum((*node)->getAttributes());
+        (*node)->setAttributes((int)val.num);
+        return ret;
+    }
     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;
@@ -318,7 +327,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" },