- 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.
This commit is contained in:
parent
916240693f
commit
f3ba7a3bd4
2 changed files with 14 additions and 17 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue