]> git.mxchange.org Git - flightgear.git/commitdiff
- add two error messages to setlistener() (invalid property or func object)
authormfranz <mfranz>
Sat, 3 Feb 2007 16:46:39 +0000 (16:46 +0000)
committermfranz <mfranz>
Sat, 3 Feb 2007 16:46:39 +0000 (16:46 +0000)
- adapt last changes to Style Of The Tile

src/Scripting/NasalSys.cxx
src/Scripting/NasalSys.hxx

index d360d211f9ee0fb7e781243a191b875702054ed2..c25c3779c646f658fa9a245f59e55dcefad9cf96 100644 (file)
@@ -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<int, FGNasalListener *>::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]);
 
index 1658350bac6177b0c1bcfcaec8324112eda225ef..06551e160dcbb33a4f5efbf16e72f2f38e37b172 100644 (file)
@@ -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