From 8a1109160bdf927951945916a57fd3aab3cde53f Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 25 Aug 2020 19:23:43 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20Nasal=20=E2=80=98removecommand=E2=80=99?= =?UTF-8?q?=20so=20it=20actually=20works.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Scripting/NasalSys.cxx | 15 ++++++++++----- src/Scripting/NasalSys.hxx | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 9cbda5166..ac24f150d 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -830,7 +830,11 @@ static naRef f_removeCommand(naContext c, naRef me, int argc, naRef* args) if ((argc < 1) || !naIsString(args[0])) naRuntimeError(c, "bad argument to removecommand()"); - globals->get_commands()->removeCommand(naStr_data(args[0])); + const string commandName(naStr_data(args[0])); + bool ok = nasalSys->removeCommand(commandName); + if (!ok) { + naRuntimeError(c, "Failed to remove command:%s", commandName.c_str()); + } return naNil(); } @@ -1777,17 +1781,18 @@ void FGNasalSys::addCommand(naRef func, const std::string& name) _commands[name] = cmd; } -void FGNasalSys::removeCommand(const std::string& name) +bool FGNasalSys::removeCommand(const std::string& name) { - NasalCommandDict::iterator it = _commands.find(name); + auto it = _commands.find(name); if (it == _commands.end()) { SG_LOG(SG_NASAL, SG_WARN, "remove of unknwon command:" << name); - return; + return false; } // will delete the NasalCommand instance - globals->get_commands()->removeCommand(name); + bool ok = globals->get_commands()->removeCommand(name); _commands.erase(it); + return ok; } void FGNasalSys::addPersistentTimer(TimerObj* pto) diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx index 0196d122c..9e544743f 100644 --- a/src/Scripting/NasalSys.hxx +++ b/src/Scripting/NasalSys.hxx @@ -95,7 +95,7 @@ public: naRef getModule(const char* moduleName); void addCommand(naRef func, const std::string& name); - void removeCommand(const std::string& name); + bool removeCommand(const std::string& name); /** * Set member of specified hash to given value