mirror of https://github.com/ArduPilot/ardupilot
AP_Scripting: Stop running scripts if the enable flag ever goes false
This commit is contained in:
parent
b5090ed78c
commit
4fc5eccb8f
|
@ -87,6 +87,7 @@ bool AP_Scripting::init(void) {
|
|||
if (!hal.scheduler->thread_create(FUNCTOR_BIND_MEMBER(&AP_Scripting::thread, void),
|
||||
"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);
|
||||
_enable = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -102,7 +103,7 @@ void AP_Scripting::thread(void) {
|
|||
lua->run();
|
||||
|
||||
// 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;
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
|
||||
bool init(void);
|
||||
|
||||
bool enabled(void) const { return _enable != 0; };
|
||||
|
||||
static AP_Scripting * get_singleton(void) { return _singleton; }
|
||||
|
||||
static const struct AP_Param::GroupInfo var_info[];
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "lua_scripts.h"
|
||||
#include <AP_HAL/AP_HAL.h>
|
||||
#include <GCS_MAVLink/GCS.h>
|
||||
#include "AP_Scripting.h"
|
||||
#include <AP_ROMFS/AP_ROMFS.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
|
||||
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 (lua_gettop(L) != 0) {
|
||||
AP_HAL::panic("Lua: Stack should be empty before running scripts");
|
||||
|
|
Loading…
Reference in New Issue