AP_Scripting: Stop running scripts if the enable flag ever goes false

This commit is contained in:
Michael du Breuil 2019-10-15 00:02:08 -07:00 committed by Andrew Tridgell
parent b5090ed78c
commit 4fc5eccb8f
3 changed files with 6 additions and 2 deletions

View File

@ -87,6 +87,7 @@ bool AP_Scripting::init(void) {
if (!hal.scheduler->thread_create(FUNCTOR_BIND_MEMBER(&AP_Scripting::thread, void), if (!hal.scheduler->thread_create(FUNCTOR_BIND_MEMBER(&AP_Scripting::thread, void),
"Scripting", SCRIPTING_STACK_SIZE, AP_HAL::Scheduler::PRIORITY_SCRIPTING, 0)) { "Scripting", SCRIPTING_STACK_SIZE, AP_HAL::Scheduler::PRIORITY_SCRIPTING, 0)) {
gcs().send_text(MAV_SEVERITY_CRITICAL, "Could not create scripting stack (%d)", SCRIPTING_STACK_SIZE); gcs().send_text(MAV_SEVERITY_CRITICAL, "Could not create scripting stack (%d)", SCRIPTING_STACK_SIZE);
_enable = 0;
return false; return false;
} }
@ -102,7 +103,7 @@ void AP_Scripting::thread(void) {
lua->run(); lua->run();
// only reachable if the lua backend has died for any reason // only reachable if the lua backend has died for any reason
gcs().send_text(MAV_SEVERITY_CRITICAL, "Scripting has died"); gcs().send_text(MAV_SEVERITY_CRITICAL, "Scripting has stopped");
} }
AP_Scripting *AP_Scripting::_singleton = nullptr; AP_Scripting *AP_Scripting::_singleton = nullptr;

View File

@ -30,6 +30,8 @@ public:
bool init(void); bool init(void);
bool enabled(void) const { return _enable != 0; };
static AP_Scripting * get_singleton(void) { return _singleton; } static AP_Scripting * get_singleton(void) { return _singleton; }
static const struct AP_Param::GroupInfo var_info[]; static const struct AP_Param::GroupInfo var_info[];

View File

@ -16,6 +16,7 @@
#include "lua_scripts.h" #include "lua_scripts.h"
#include <AP_HAL/AP_HAL.h> #include <AP_HAL/AP_HAL.h>
#include <GCS_MAVLink/GCS.h> #include <GCS_MAVLink/GCS.h>
#include "AP_Scripting.h"
#include <AP_ROMFS/AP_ROMFS.h> #include <AP_ROMFS/AP_ROMFS.h>
#include "lua_generated_bindings.h" #include "lua_generated_bindings.h"
@ -348,7 +349,7 @@ void lua_scripts::run(void) {
// Scan the filesystem in an appropriate manner and autostart scripts // Scan the filesystem in an appropriate manner and autostart scripts
load_all_scripts_in_dir(L, SCRIPTING_DIRECTORY); load_all_scripts_in_dir(L, SCRIPTING_DIRECTORY);
while (true) { while (AP_Scripting::get_singleton()->enabled()) {
#if defined(AP_SCRIPTING_CHECKS) && AP_SCRIPTING_CHECKS >= 1 #if defined(AP_SCRIPTING_CHECKS) && AP_SCRIPTING_CHECKS >= 1
if (lua_gettop(L) != 0) { if (lua_gettop(L) != 0) {
AP_HAL::panic("Lua: Stack should be empty before running scripts"); AP_HAL::panic("Lua: Stack should be empty before running scripts");