don't abort fgfs only because a nasal script called a property function
with an invalid path, as in getprop("/sim/model/737") or x.getNode("f:1"). Forward sg's error message to the Nasal runtime error function instead, so you get something like: Nasal runtime error: name must begin with alpha or '_' at /home/m/fgfs/Base.local/Nasal/props.nas, line 30 Unfortunately, the location points to the line where the ghost wrapper sits, rather than the offending script line.
This commit is contained in:
parent
fdb9e94af3
commit
e0b1d12a60
2 changed files with 55 additions and 21 deletions
|
@ -124,11 +124,16 @@ void FGNasalSys::hashset(naRef hash, const char* key, naRef val)
|
|||
static SGPropertyNode* findnode(naContext c, naRef* vec, int len)
|
||||
{
|
||||
SGPropertyNode* p = globals->get_props();
|
||||
for(int i=0; i<len; i++) {
|
||||
naRef a = vec[i];
|
||||
if(!naIsString(a)) return 0;
|
||||
p = p->getNode(naStr_data(a));
|
||||
if(p == 0) return 0;
|
||||
try {
|
||||
for(int i=0; i<len; i++) {
|
||||
naRef a = vec[i];
|
||||
if(!naIsString(a)) return 0;
|
||||
p = p->getNode(naStr_data(a));
|
||||
if(p == 0) return 0;
|
||||
}
|
||||
} catch (const string& err) {
|
||||
naRuntimeError(c, (char *)err.c_str());
|
||||
return 0;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
@ -185,8 +190,12 @@ static naRef f_setprop(naContext c, naRef me, int argc, naRef* args)
|
|||
|
||||
SGPropertyNode* props = globals->get_props();
|
||||
naRef val = args[argc-1];
|
||||
if(naIsString(val)) props->setStringValue(buf, naStr_data(val));
|
||||
else props->setDoubleValue(buf, naNumValue(val).num);
|
||||
try {
|
||||
if(naIsString(val)) props->setStringValue(buf, naStr_data(val));
|
||||
else props->setDoubleValue(buf, naNumValue(val).num);
|
||||
} catch (const string& err) {
|
||||
naRuntimeError(c, (char *)err.c_str());
|
||||
}
|
||||
return naNil();
|
||||
#undef BUFLEN
|
||||
}
|
||||
|
|
|
@ -157,10 +157,15 @@ static naRef f_getChild(naContext c, naRef me, int argc, naRef* args)
|
|||
naRef idx = naNumValue(naVec_get(argv, 1));
|
||||
bool create = naTrue(naVec_get(argv, 2));
|
||||
SGPropertyNode* n;
|
||||
if(naIsNil(idx) || !naIsNum(idx)) {
|
||||
n = (*node)->getChild(naStr_data(child), create);
|
||||
} else {
|
||||
n = (*node)->getChild(naStr_data(child), (int)idx.num, create);
|
||||
try {
|
||||
if(naIsNil(idx) || !naIsNum(idx)) {
|
||||
n = (*node)->getChild(naStr_data(child), create);
|
||||
} else {
|
||||
n = (*node)->getChild(naStr_data(child), (int)idx.num, create);
|
||||
}
|
||||
} catch (const string& err) {
|
||||
naRuntimeError(c, (char *)err.c_str());
|
||||
return naNil();
|
||||
}
|
||||
if(!n) return naNil();
|
||||
return propNodeGhostCreate(c, n);
|
||||
|
@ -178,10 +183,15 @@ static naRef f_getChildren(naContext c, naRef me, int argc, naRef* args)
|
|||
// Get all children of a specified name
|
||||
naRef name = naVec_get(argv, 0);
|
||||
if(!naIsString(name)) return naNil();
|
||||
vector<SGPropertyNode_ptr> children
|
||||
= (*node)->getChildren(naStr_data(name));
|
||||
for(unsigned int i=0; i<children.size(); i++)
|
||||
naVec_append(result, propNodeGhostCreate(c, children[i]));
|
||||
try {
|
||||
vector<SGPropertyNode_ptr> children
|
||||
= (*node)->getChildren(naStr_data(name));
|
||||
for(unsigned int i=0; i<children.size(); i++)
|
||||
naVec_append(result, propNodeGhostCreate(c, children[i]));
|
||||
} catch (const string& err) {
|
||||
naRuntimeError(c, (char *)err.c_str());
|
||||
return naNil();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -192,7 +202,11 @@ 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();
|
||||
(*node)->removeChild(naStr_data(child), (int)index.num, false);
|
||||
try {
|
||||
(*node)->removeChild(naStr_data(child), (int)index.num, false);
|
||||
} catch (const string& err) {
|
||||
naRuntimeError(c, (char *)err.c_str());
|
||||
}
|
||||
return naNil();
|
||||
}
|
||||
|
||||
|
@ -208,10 +222,15 @@ static naRef f_removeChildren(naContext c, naRef me, int argc, naRef* args)
|
|||
// Remove all children of a specified name
|
||||
naRef name = naVec_get(argv, 0);
|
||||
if(!naIsString(name)) return naNil();
|
||||
vector<SGPropertyNode_ptr> children
|
||||
= (*node)->removeChildren(naStr_data(name), false);
|
||||
for(unsigned int i=0; i<children.size(); i++)
|
||||
naVec_append(result, propNodeGhostCreate(c, children[i]));
|
||||
try {
|
||||
vector<SGPropertyNode_ptr> children
|
||||
= (*node)->removeChildren(naStr_data(name), false);
|
||||
for(unsigned int i=0; i<children.size(); i++)
|
||||
naVec_append(result, propNodeGhostCreate(c, children[i]));
|
||||
} catch (const string& err) {
|
||||
naRuntimeError(c, (char *)err.c_str());
|
||||
return naNil();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -222,7 +241,13 @@ static naRef f_getNode(naContext c, naRef me, int argc, naRef* args)
|
|||
naRef path = naVec_get(argv, 0);
|
||||
bool create = naTrue(naVec_get(argv, 1));
|
||||
if(!naIsString(path)) return naNil();
|
||||
SGPropertyNode* n = (*node)->getNode(naStr_data(path), create);
|
||||
SGPropertyNode* n;
|
||||
try {
|
||||
n = (*node)->getNode(naStr_data(path), create);
|
||||
} catch (const string& err) {
|
||||
naRuntimeError(c, (char *)err.c_str());
|
||||
return naNil();
|
||||
}
|
||||
return propNodeGhostCreate(c, n);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue