AP_Scripting: use AP_Filesystem API
This commit is contained in:
parent
667b4e045a
commit
b577787f68
@ -43,3 +43,10 @@
|
||||
|
||||
#endif
|
||||
|
||||
// load posix compatibility functions
|
||||
#include <AP_Filesystem/posix_compat.h>
|
||||
|
||||
#define lua_writestring(s,l) printf("%s", s)
|
||||
#define lua_writestringerror(s,l) lua_writestring(s,l)
|
||||
|
||||
|
||||
|
@ -2,6 +2,9 @@
|
||||
// Lua header files for C++
|
||||
// <<extern "C">> not supplied automatically because Lua also compiles as C++
|
||||
|
||||
#include <AP_Filesystem/AP_Filesystem.h>
|
||||
#include <AP_Filesystem/posix_compat.h>
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
|
@ -18,14 +18,6 @@
|
||||
#include <GCS_MAVLink/GCS.h>
|
||||
#include <AP_ROMFS/AP_ROMFS.h>
|
||||
|
||||
#if HAL_OS_POSIX_IO
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#if HAL_OS_FATFS_IO
|
||||
#include <stdio.h>
|
||||
#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) {
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <AP_Param/AP_Param.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <AP_Filesystem/posix_compat.h>
|
||||
#include "lua_bindings.h"
|
||||
|
||||
class lua_scripts
|
||||
|
Loading…
Reference in New Issue
Block a user