From b577787f680db3858d802e709249a819a4098146 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 1 Aug 2019 20:55:03 +1000 Subject: [PATCH] AP_Scripting: use AP_Filesystem API --- libraries/AP_Scripting/lua/src/lprefix.h | 7 +++++++ libraries/AP_Scripting/lua/src/lua.hpp | 3 +++ libraries/AP_Scripting/lua_scripts.cpp | 14 +++----------- libraries/AP_Scripting/lua_scripts.h | 1 + 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libraries/AP_Scripting/lua/src/lprefix.h b/libraries/AP_Scripting/lua/src/lprefix.h index 9a749a3f30..7cfa8f3e2a 100644 --- a/libraries/AP_Scripting/lua/src/lprefix.h +++ b/libraries/AP_Scripting/lua/src/lprefix.h @@ -43,3 +43,10 @@ #endif +// load posix compatibility functions +#include + +#define lua_writestring(s,l) printf("%s", s) +#define lua_writestringerror(s,l) lua_writestring(s,l) + + diff --git a/libraries/AP_Scripting/lua/src/lua.hpp b/libraries/AP_Scripting/lua/src/lua.hpp index ec417f5946..0ab35aba54 100644 --- a/libraries/AP_Scripting/lua/src/lua.hpp +++ b/libraries/AP_Scripting/lua/src/lua.hpp @@ -2,6 +2,9 @@ // Lua header files for C++ // <> not supplied automatically because Lua also compiles as C++ +#include +#include + extern "C" { #include "lua.h" #include "lualib.h" diff --git a/libraries/AP_Scripting/lua_scripts.cpp b/libraries/AP_Scripting/lua_scripts.cpp index 7ffda7766a..503567eca5 100644 --- a/libraries/AP_Scripting/lua_scripts.cpp +++ b/libraries/AP_Scripting/lua_scripts.cpp @@ -18,14 +18,6 @@ #include #include -#if HAL_OS_POSIX_IO -#include -#endif - -#if HAL_OS_FATFS_IO -#include -#endif - #include "lua_generated_bindings.h" #ifndef SCRIPTING_DIRECTORY @@ -121,14 +113,14 @@ void lua_scripts::load_all_scripts_in_dir(lua_State *L, const char *dirname) { return; } - DIR *d = opendir(dirname); + DIR *d = AP::FS().opendir(dirname); if (d == nullptr) { gcs().send_text(MAV_SEVERITY_INFO, "Lua: Could not find a scripts directory"); return; } // load anything that ends in .lua - for (struct dirent *de=readdir(d); de; de=readdir(d)) { + for (struct dirent *de=AP::FS().readdir(d); de; de=AP::FS().readdir(d)) { uint8_t length = strlen(de->d_name); if (length < 5) { // not long enough @@ -157,7 +149,7 @@ void lua_scripts::load_all_scripts_in_dir(lua_State *L, const char *dirname) { reschedule_script(script); } - closedir(d); + AP::FS().closedir(d); } void lua_scripts::run_next_script(lua_State *L) { diff --git a/libraries/AP_Scripting/lua_scripts.h b/libraries/AP_Scripting/lua_scripts.h index 278c10cb65..b3ac68eaac 100644 --- a/libraries/AP_Scripting/lua_scripts.h +++ b/libraries/AP_Scripting/lua_scripts.h @@ -18,6 +18,7 @@ #include #include +#include #include "lua_bindings.h" class lua_scripts