From f3ba7a3bd4250d8ddbd7e095456f0b0360d3a7e7 Mon Sep 17 00:00:00 2001 From: mfranz Date: Sat, 7 Feb 2009 23:52:12 +0000 Subject: [PATCH] - pass return values in set{,Bool,Int,Double}Value() and setprop() - 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 | 9 ++++----- src/Scripting/nasal-props.cxx | 22 ++++++++++------------ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 1941712ec..d6277ae69 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -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 } diff --git a/src/Scripting/nasal-props.cxx b/src/Scripting/nasal-props.cxx index 123af7539..0b97e42ad 100644 --- a/src/Scripting/nasal-props.cxx +++ b/src/Scripting/nasal-props.cxx @@ -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) -- 2.39.5