From 200abfef2d2427923657ef949093be41db940a43 Mon Sep 17 00:00:00 2001 From: mfranz Date: Tue, 16 Oct 2007 15:15:41 +0000 Subject: [PATCH] - listener: re-order and change callback function args; simplify code - make code look like Andy wrote it (so people know whom to blame :-) - nasal-props.cxx: warning-- --- src/Scripting/NasalSys.cxx | 38 +++++++++++++---------------------- src/Scripting/NasalSys.hxx | 2 +- src/Scripting/nasal-props.cxx | 2 +- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 62deef8b0..b545c33b2 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -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) diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx index 9fcc98ae9..a7e98fd0a 100644 --- a/src/Scripting/NasalSys.hxx +++ b/src/Scripting/NasalSys.hxx @@ -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; diff --git a/src/Scripting/nasal-props.cxx b/src/Scripting/nasal-props.cxx index 87afb1d93..b2de4d02b 100644 --- a/src/Scripting/nasal-props.cxx +++ b/src/Scripting/nasal-props.cxx @@ -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" }, -- 2.39.5