diff --git a/libraries/AP_Scripting/AP_Scripting.cpp b/libraries/AP_Scripting/AP_Scripting.cpp index add227b54a..e08c1afee4 100644 --- a/libraries/AP_Scripting/AP_Scripting.cpp +++ b/libraries/AP_Scripting/AP_Scripting.cpp @@ -96,6 +96,15 @@ void AP_Scripting::init(void) { return; } + const char *dir_name = SCRIPTING_DIRECTORY; + + if (!AP::FS().mkdir(dir_name)) { + gcs().send_text(MAV_SEVERITY_INFO, "Lua: created new directory (%s)", dir_name); + } else if (errno != EEXIST) { + gcs().send_text(MAV_SEVERITY_INFO, "Lua: failed to create (%s)", dir_name); + return; + } + 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); diff --git a/libraries/AP_Scripting/lua_scripts.cpp b/libraries/AP_Scripting/lua_scripts.cpp index 244c09f644..3b6f85392d 100644 --- a/libraries/AP_Scripting/lua_scripts.cpp +++ b/libraries/AP_Scripting/lua_scripts.cpp @@ -20,14 +20,6 @@ #include -#ifndef SCRIPTING_DIRECTORY - #if HAL_OS_FATFS_IO - #define SCRIPTING_DIRECTORY "/APM/scripts" - #else - #define SCRIPTING_DIRECTORY "./scripts" - #endif //HAL_OS_FATFS_IO -#endif // SCRIPTING_DIRECTORY - extern const AP_HAL::HAL& hal; bool lua_scripts::overtime; diff --git a/libraries/AP_Scripting/lua_scripts.h b/libraries/AP_Scripting/lua_scripts.h index f2f7be8708..ba684e2119 100644 --- a/libraries/AP_Scripting/lua_scripts.h +++ b/libraries/AP_Scripting/lua_scripts.h @@ -30,6 +30,14 @@ #endif //HAL_OS_FATFS_IO #endif // REPL_DIRECTORY +#ifndef SCRIPTING_DIRECTORY + #if HAL_OS_FATFS_IO + #define SCRIPTING_DIRECTORY "/APM/scripts" + #else + #define SCRIPTING_DIRECTORY "./scripts" + #endif //HAL_OS_FATFS_IO +#endif // SCRIPTING_DIRECTORY + #ifndef REPL_IN #define REPL_IN REPL_DIRECTORY "/in" #endif // REPL_IN