AP_Scripting: add DIR_DISABLE param
This commit is contained in:
parent
2bdcadd785
commit
97b44dfe71
@ -101,6 +101,14 @@ const AP_Param::GroupInfo AP_Scripting::var_info[] = {
|
||||
// @User: Standard
|
||||
AP_GROUPINFO("USER4", 8, AP_Scripting, _user[3], 0.0),
|
||||
|
||||
// @Param: DIR_DISABLE
|
||||
// @DisplayName: Directory disable
|
||||
// @Description: This will stop scripts being loaded from the given locations
|
||||
// @Bitmask: 0:ROMFS, 1:APM/scripts
|
||||
// @RebootRequired: True
|
||||
// @User: Advanced
|
||||
AP_GROUPINFO("DIR_DISABLE", 9, AP_Scripting, _dir_disable, 0),
|
||||
|
||||
AP_GROUPEND
|
||||
};
|
||||
|
||||
|
@ -50,6 +50,12 @@ public:
|
||||
bool session;
|
||||
} terminal;
|
||||
|
||||
enum class SCR_DIR {
|
||||
ROMFS = 1 << 0,
|
||||
SCRIPTS = 1 << 1,
|
||||
};
|
||||
uint16_t get_disabled_dir() { return uint16_t(_dir_disable.get());}
|
||||
|
||||
private:
|
||||
|
||||
bool repl_start(void);
|
||||
@ -63,6 +69,7 @@ private:
|
||||
AP_Int32 _script_vm_exec_count;
|
||||
AP_Int32 _script_heap_size;
|
||||
AP_Int8 _debug_level;
|
||||
AP_Int16 _dir_disable;
|
||||
|
||||
bool _init_failed; // true if memory allocation failed
|
||||
|
||||
|
@ -363,8 +363,20 @@ void lua_scripts::run(void) {
|
||||
load_generated_bindings(L);
|
||||
|
||||
// Scan the filesystem in an appropriate manner and autostart scripts
|
||||
load_all_scripts_in_dir(L, SCRIPTING_DIRECTORY);
|
||||
load_all_scripts_in_dir(L, "@ROMFS/scripts");
|
||||
// Skip those directores disabled with SCR_DIR_DISABLE param
|
||||
uint16_t dir_disable = AP_Scripting::get_singleton()->get_disabled_dir();
|
||||
bool loaded = false;
|
||||
if ((dir_disable & uint16_t(AP_Scripting::SCR_DIR::SCRIPTS)) == 0) {
|
||||
load_all_scripts_in_dir(L, SCRIPTING_DIRECTORY);
|
||||
loaded = true;
|
||||
}
|
||||
if ((dir_disable & uint16_t(AP_Scripting::SCR_DIR::ROMFS)) == 0) {
|
||||
load_all_scripts_in_dir(L, "@ROMFS/scripts");
|
||||
loaded = true;
|
||||
}
|
||||
if (!loaded) {
|
||||
gcs().send_text(MAV_SEVERITY_CRITICAL, "Lua: All directory's disabled see SCR_DIR_DISABLE");
|
||||
}
|
||||
|
||||
#ifndef __clang_analyzer__
|
||||
succeeded_initial_load = true;
|
||||
|
Loading…
Reference in New Issue
Block a user