Skip to content

Commit

Permalink
AP_Scripting: add DIR_DISABLE param
Browse files Browse the repository at this point in the history
  • Loading branch information
IamPete1 authored and tridge committed Oct 28, 2020
1 parent 2bdcadd commit 97b44df
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions libraries/AP_Scripting/AP_Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
7 changes: 7 additions & 0 deletions libraries/AP_Scripting/AP_Scripting.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class AP_Scripting
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);
Expand All @@ -63,6 +69,7 @@ class AP_Scripting
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

Expand Down
16 changes: 14 additions & 2 deletions libraries/AP_Scripting/lua_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 97b44df

Please sign in to comment.