1
0
Fork 0

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:
mfranz 2006-05-23 18:55:38 +00:00
parent fdb9e94af3
commit e0b1d12a60
2 changed files with 55 additions and 21 deletions

View file

@ -124,12 +124,17 @@ void FGNasalSys::hashset(naRef hash, const char* key, naRef val)
static SGPropertyNode* findnode(naContext c, naRef* vec, int len) static SGPropertyNode* findnode(naContext c, naRef* vec, int len)
{ {
SGPropertyNode* p = globals->get_props(); SGPropertyNode* p = globals->get_props();
try {
for(int i=0; i<len; i++) { for(int i=0; i<len; i++) {
naRef a = vec[i]; naRef a = vec[i];
if(!naIsString(a)) return 0; if(!naIsString(a)) return 0;
p = p->getNode(naStr_data(a)); p = p->getNode(naStr_data(a));
if(p == 0) return 0; if(p == 0) return 0;
} }
} catch (const string& err) {
naRuntimeError(c, (char *)err.c_str());
return 0;
}
return p; return p;
} }
@ -185,8 +190,12 @@ static naRef f_setprop(naContext c, naRef me, int argc, naRef* args)
SGPropertyNode* props = globals->get_props(); SGPropertyNode* props = globals->get_props();
naRef val = args[argc-1]; naRef val = args[argc-1];
try {
if(naIsString(val)) props->setStringValue(buf, naStr_data(val)); if(naIsString(val)) props->setStringValue(buf, naStr_data(val));
else props->setDoubleValue(buf, naNumValue(val).num); else props->setDoubleValue(buf, naNumValue(val).num);
} catch (const string& err) {
naRuntimeError(c, (char *)err.c_str());
}
return naNil(); return naNil();
#undef BUFLEN #undef BUFLEN
} }

View file

@ -157,11 +157,16 @@ static naRef f_getChild(naContext c, naRef me, int argc, naRef* args)
naRef idx = naNumValue(naVec_get(argv, 1)); naRef idx = naNumValue(naVec_get(argv, 1));
bool create = naTrue(naVec_get(argv, 2)); bool create = naTrue(naVec_get(argv, 2));
SGPropertyNode* n; SGPropertyNode* n;
try {
if(naIsNil(idx) || !naIsNum(idx)) { if(naIsNil(idx) || !naIsNum(idx)) {
n = (*node)->getChild(naStr_data(child), create); n = (*node)->getChild(naStr_data(child), create);
} else { } else {
n = (*node)->getChild(naStr_data(child), (int)idx.num, create); 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(); if(!n) return naNil();
return propNodeGhostCreate(c, n); 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 // Get all children of a specified name
naRef name = naVec_get(argv, 0); naRef name = naVec_get(argv, 0);
if(!naIsString(name)) return naNil(); if(!naIsString(name)) return naNil();
try {
vector<SGPropertyNode_ptr> children vector<SGPropertyNode_ptr> children
= (*node)->getChildren(naStr_data(name)); = (*node)->getChildren(naStr_data(name));
for(unsigned int i=0; i<children.size(); i++) for(unsigned int i=0; i<children.size(); i++)
naVec_append(result, propNodeGhostCreate(c, children[i])); naVec_append(result, propNodeGhostCreate(c, children[i]));
} catch (const string& err) {
naRuntimeError(c, (char *)err.c_str());
return naNil();
}
} }
return result; 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 child = naVec_get(argv, 0);
naRef index = naVec_get(argv, 1); naRef index = naVec_get(argv, 1);
if(!naIsString(child) || !naIsNum(index)) return naNil(); if(!naIsString(child) || !naIsNum(index)) return naNil();
try {
(*node)->removeChild(naStr_data(child), (int)index.num, false); (*node)->removeChild(naStr_data(child), (int)index.num, false);
} catch (const string& err) {
naRuntimeError(c, (char *)err.c_str());
}
return naNil(); 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 // Remove all children of a specified name
naRef name = naVec_get(argv, 0); naRef name = naVec_get(argv, 0);
if(!naIsString(name)) return naNil(); if(!naIsString(name)) return naNil();
try {
vector<SGPropertyNode_ptr> children vector<SGPropertyNode_ptr> children
= (*node)->removeChildren(naStr_data(name), false); = (*node)->removeChildren(naStr_data(name), false);
for(unsigned int i=0; i<children.size(); i++) for(unsigned int i=0; i<children.size(); i++)
naVec_append(result, propNodeGhostCreate(c, children[i])); naVec_append(result, propNodeGhostCreate(c, children[i]));
} catch (const string& err) {
naRuntimeError(c, (char *)err.c_str());
return naNil();
}
} }
return result; return result;
} }
@ -222,7 +241,13 @@ static naRef f_getNode(naContext c, naRef me, int argc, naRef* args)
naRef path = naVec_get(argv, 0); naRef path = naVec_get(argv, 0);
bool create = naTrue(naVec_get(argv, 1)); bool create = naTrue(naVec_get(argv, 1));
if(!naIsString(path)) return naNil(); 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); return propNodeGhostCreate(c, n);
} }