]> git.mxchange.org Git - flightgear.git/commitdiff
- listener: re-order and change callback function args; simplify code
authormfranz <mfranz>
Tue, 16 Oct 2007 15:15:41 +0000 (15:15 +0000)
committermfranz <mfranz>
Tue, 16 Oct 2007 15:15:41 +0000 (15:15 +0000)
- make code look like Andy wrote it (so people know whom to blame :-)
- nasal-props.cxx: warning--

src/Scripting/NasalSys.cxx
src/Scripting/NasalSys.hxx
src/Scripting/nasal-props.cxx

index 62deef8b060d8a38fa9c56eb400a805281824ae9..b545c33b24a798906fd888c10682b3c49d407646 100644 (file)
@@ -1005,48 +1005,38 @@ FGNasalListener::~FGNasalListener()
     _nas->gcRelease(_gcKey);
 }
 
-void FGNasalListener::call(SGPropertyNode* cmdarg, int argc, naRef* args)
+void FGNasalListener::call(SGPropertyNode* which, naRef mode)
 {
-    if(_active || _dead)
-        return;
+    if(_active || _dead) return;
     SG_LOG(SG_NASAL, SG_DEBUG, "trigger listener #" << _id);
     _active++;
-    _nas->_cmdArg = cmdarg;
-    _nas->call(_handler, argc, args, naNil());
+    naRef arg[4];
+    arg[0] = _nas->propNodeGhost(which);
+    arg[1] = _nas->propNodeGhost(_node);
+    arg[2] = mode;                  // value changed, child added/removed
+    arg[3] = naNum(_node != which); // child event?
+    _nas->_cmdArg = _node;
+    _nas->call(_handler, 4, arg, naNil());
     _active--;
 }
 
 void FGNasalListener::valueChanged(SGPropertyNode* node)
 {
-    if(_type < 2 && node != _node)
-        return;
+    if(_type < 2 && node != _node) return;
+    if(_type > 0 || changed(_node) || _first_call)
+        call(node, naNum(0));
 
-    if(_type > 0 || changed(_node) || _first_call) {
-        naRef arg[3];
-        arg[0] = _nas->propNodeGhost(_node);
-        arg[1] = _nas->propNodeGhost(node);
-        arg[2] = naNil();
-        call(_node, 3, arg);
-    }
     _first_call = false;
 }
 
 void FGNasalListener::childAdded(SGPropertyNode*, SGPropertyNode* child)
 {
-    naRef arg[3];
-    arg[0] = _nas->propNodeGhost(_node);
-    arg[1] = _nas->propNodeGhost(child);
-    arg[2] = naNum(1);
-    call(_node, 3, arg);
+    if(_type == 2) call(child, naNum(1));
 }
 
 void FGNasalListener::childRemoved(SGPropertyNode*, SGPropertyNode* child)
 {
-    naRef arg[3];
-    arg[0] = _nas->propNodeGhost(_node);
-    arg[1] = _nas->propNodeGhost(child);
-    arg[2] = naNum(0);
-    call(_node, 3, arg);
+    if(_type == 2) call(child, naNum(-1));
 }
 
 bool FGNasalListener::changed(SGPropertyNode* node)
index 9fcc98ae90e567c6d7869442e824d023200c0382..a7e98fd0a435c9397cc74daf5a25a2850f68f64d 100644 (file)
@@ -141,7 +141,7 @@ public:
 
 private:
     bool changed(SGPropertyNode* node);
-    void call(SGPropertyNode* cmdarg, int argc, naRef* args);
+    void call(SGPropertyNode* which, naRef mode);
 
     friend class FGNasalSys;
     SGPropertyNode_ptr _node;
index 87afb1d93160d2c28ecf7cac0612d71249f011b7..b2de4d02b1adf9698ae42caa4b57863f465aff94 100644 (file)
@@ -326,7 +326,7 @@ static naRef f_globals(naContext c, naRef me, int argc, naRef* args)
 
 static struct {
     naCFunction func;
-    char* name;
+    const char* name;
 } propfuncs[] = {
     { f_getType, "_getType" },
     { f_getAttribute, "_getAttribute" },