]> git.mxchange.org Git - flightgear.git/commitdiff
- pass return values in set{,Bool,Int,Double}Value() and setprop()
authormfranz <mfranz>
Sat, 7 Feb 2009 23:52:12 +0000 (23:52 +0000)
committerTim Moore <timoore@redhat.com>
Mon, 9 Feb 2009 23:22:16 +0000 (00:22 +0100)
- make some char* "const" to silence warnings

This removes the warning that (rarely) occurred if one wrote to a
write protected property with setprop(). While this was a useful
hint, it needlessly floods the terminal if one protected a property
intentionally. (Consider to add an SG_DEBUG warning instead.) It's
now the caller's job to check for the result if it actually cares.

src/Scripting/NasalSys.cxx
src/Scripting/nasal-props.cxx

index 1941712eca92487f1ccd2b8add2ea9a9fc0cadba..d6277ae69b5efa47d4cd45100344c5dfc10b4b15 100644 (file)
@@ -223,20 +223,19 @@ static naRef f_setprop(naContext c, naRef me, int argc, naRef* args)
 
     SGPropertyNode* props = globals->get_props();
     naRef val = args[argc-1];
+    bool result = false;
     try {
-        bool r;
-        if(naIsString(val)) r = props->setStringValue(buf, naStr_data(val));
+        if(naIsString(val)) result = props->setStringValue(buf, naStr_data(val));
         else {
             naRef n = naNumValue(val);
             if(naIsNil(n))
                 naRuntimeError(c, "setprop() value is not string or number");
-            r = props->setDoubleValue(buf, n.num);
+            result = props->setDoubleValue(buf, n.num);
         }
-        if(!r) naRuntimeError(c, "setprop(): property is not writable");
     } catch (const string& err) {
         naRuntimeError(c, (char *)err.c_str());
     }
-    return naNil();
+    return naNum(result);
 #undef BUFLEN
 }
 
index 123af75391127d0eddf19062d928d2a4548309aa..0b97e42add4dbf74ecb8fc561659cabb88ec10be 100644 (file)
@@ -59,7 +59,7 @@ naRef FGNasalSys::propNodeGhost(SGPropertyNode* handle)
 static naRef f_getType(naContext c, naRef me, int argc, naRef* args)
 {
     NODEARG();
-    char* t = "unknown";
+    const char* t = "unknown";
     switch((*node)->getType()) {
     case SGPropertyNode::NONE:   t = "NONE";   break;
     case SGPropertyNode::ALIAS:  t = "ALIAS";  break;
@@ -79,7 +79,7 @@ static naRef f_getAttribute(naContext c, naRef me, int argc, naRef* args)
     NODEARG();
     if(naVec_size(argv) == 0) return naNum(unsigned((*node)->getAttributes()));
     naRef val = naVec_get(argv, 0);
-    char *a = naStr_data(val);
+    const char *a = naStr_data(val);
     SGPropertyNode::Attribute attr;
     if(!a) a = "";
     if(!strcmp(a, "last")) return naNum(SGPropertyNode::LAST_USED_ATTRIBUTE);
@@ -111,7 +111,7 @@ static naRef f_setAttribute(naContext c, naRef me, int argc, naRef* args)
         return ret;
     }
     SGPropertyNode::Attribute attr;
-    char *a = naStr_data(val);
+    const char *a = naStr_data(val);
     if(!a) a = "";
     if(!strcmp(a, "readable"))         attr = SGPropertyNode::READ;
     else if(!strcmp(a, "writable"))    attr = SGPropertyNode::WRITE;
@@ -160,14 +160,15 @@ static naRef f_setValue(naContext c, naRef me, int argc, naRef* args)
 {
     NODEARG();
     naRef val = naVec_get(argv, 0);
-    if(naIsString(val)) (*node)->setStringValue(naStr_data(val));
+    bool result = false;
+    if(naIsString(val)) result = (*node)->setStringValue(naStr_data(val));
     else {
         naRef n = naNumValue(val);
         if(naIsNil(n))
             naRuntimeError(c, "props.setValue() with non-number");
-        (*node)->setDoubleValue(naNumValue(val).num);
+        result = (*node)->setDoubleValue(naNumValue(val).num);
     }
-    return naNil();
+    return naNum(result);
 }
 
 static naRef f_setIntValue(naContext c, naRef me, int argc, naRef* args)
@@ -184,16 +185,14 @@ static naRef f_setIntValue(naContext c, naRef me, int argc, naRef* args)
     double tmp2 = tmp1.num;
     int iv = (int)tmp2;
 
-    (*node)->setIntValue(iv);
-    return naNil();
+    return naNum((*node)->setIntValue(iv));
 }
 
 static naRef f_setBoolValue(naContext c, naRef me, int argc, naRef* args)
 {
     NODEARG();
     naRef val = naVec_get(argv, 0);
-    (*node)->setBoolValue(naTrue(val) ? true : false);
-    return naNil();
+    return naNum((*node)->setBoolValue(naTrue(val) ? true : false));
 }
 
 static naRef f_setDoubleValue(naContext c, naRef me, int argc, naRef* args)
@@ -202,8 +201,7 @@ static naRef f_setDoubleValue(naContext c, naRef me, int argc, naRef* args)
     naRef r = naNumValue(naVec_get(argv, 0));
     if(naIsNil(r))
         naRuntimeError(c, "props.setDoubleValue() with non-number");
-    (*node)->setDoubleValue(r.num);
-    return naNil();
+    return naNum((*node)->setDoubleValue(r.num));
 }
 
 static naRef f_getParent(naContext c, naRef me, int argc, naRef* args)