From: mfranz Date: Sat, 3 Feb 2007 16:46:39 +0000 (+0000) Subject: - add two error messages to setlistener() (invalid property or func object) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=862196a3ab1ae2097082aeb2a3c41c80f72a36bf;p=flightgear.git - add two error messages to setlistener() (invalid property or func object) - adapt last changes to Style Of The Tile --- diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index d360d211f..c25c3779c 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -269,7 +269,7 @@ static naRef f_settimer(naContext c, naRef me, int argc, naRef* args) static naRef f_setlistener(naContext c, naRef me, int argc, naRef* args) { FGNasalSys* nasal = (FGNasalSys*)globals->get_subsystem("nasal"); - return nasal->setListener(argc, args); + return nasal->setListener(c, argc, args); } // removelistener(int) extension function. Falls through to @@ -434,10 +434,10 @@ void FGNasalSys::update(double) if(_purgeListeners) { _purgeListeners = false; map::iterator it; - for ( it = _listener.begin(); it != _listener.end(); ) { + for(it = _listener.begin(); it != _listener.end();) { FGNasalListener *nl = it->second; if(nl->_dead) { - _listener.erase( it++ ); + _listener.erase(it++); delete nl; } else { ++it; @@ -668,21 +668,26 @@ int FGNasalSys::_listenerId = 0; // If the bool is true, then the listener is executed initially. The // setlistener() function returns a unique id number, that can be used // as argument to the removelistener() function. -naRef FGNasalSys::setListener(int argc, naRef* args) +naRef FGNasalSys::setListener(naContext c, int argc, naRef* args) { SGPropertyNode_ptr node; naRef prop = argc > 0 ? args[0] : naNil(); if(naIsString(prop)) node = fgGetNode(naStr_data(prop), true); else if(naIsGhost(prop)) node = *(SGPropertyNode_ptr*)naGhost_ptr(prop); - else return naNil(); + else { + naRuntimeError(c, "setlistener() with invalid property argument"); + return naNil(); + } if(node->isTied()) SG_LOG(SG_NASAL, SG_DEBUG, "Attaching listener to tied property " << node->getPath()); naRef handler = argc > 1 ? args[1] : naNil(); - if(!(naIsCode(handler) || naIsCCode(handler) || naIsFunc(handler))) + if(!(naIsCode(handler) || naIsCCode(handler) || naIsFunc(handler))) { + naRuntimeError(c, "setlistener() with invalid function argument"); return naNil(); + } bool initial = argc > 2 && naTrue(args[2]); diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx index 1658350ba..06551e160 100644 --- a/src/Scripting/NasalSys.hxx +++ b/src/Scripting/NasalSys.hxx @@ -43,7 +43,7 @@ public: void setTimer(int argc, naRef* args); // Implementation of the setlistener extension function - naRef setListener(int argc, naRef* args); + naRef setListener(naContext c, int argc, naRef* args); naRef removeListener(naContext c, int argc, naRef* args); // Returns a ghost wrapper for the current _cmdArg