From e0b1d12a60a6bae20a0c5a73eea98286b4f04047 Mon Sep 17 00:00:00 2001 From: mfranz Date: Tue, 23 May 2006 18:55:38 +0000 Subject: [PATCH] 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. --- src/Scripting/NasalSys.cxx | 23 ++++++++++----- src/Scripting/nasal-props.cxx | 53 ++++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 5343c06fa..9b9eb5a29 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -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; igetNode(naStr_data(a)); - if(p == 0) return 0; + try { + for(int i=0; igetNode(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 } diff --git a/src/Scripting/nasal-props.cxx b/src/Scripting/nasal-props.cxx index bd3f9411c..aba10f6a5 100644 --- a/src/Scripting/nasal-props.cxx +++ b/src/Scripting/nasal-props.cxx @@ -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 children - = (*node)->getChildren(naStr_data(name)); - for(unsigned int i=0; i children + = (*node)->getChildren(naStr_data(name)); + for(unsigned int i=0; iremoveChild(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 children - = (*node)->removeChildren(naStr_data(name), false); - for(unsigned int i=0; i children + = (*node)->removeChildren(naStr_data(name), false); + for(unsigned int i=0; igetNode(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); } -- 2.39.5