mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-11-08 10:38:44 +08:00
AP_Scripting: added isdirectory()
This commit is contained in:
1 parent
9065baa329
commit
3446ff78d7
4 files changed
+26
No files matched your search
@@ -720,6 +720,25 @@ int lua_dirlist(lua_State *L) {
|
||||
return 1; /* table is already on top */
|
||||
}
|
||||
|
||||
/*
|
||||
return true if path is a directory
|
||||
*/
|
||||
int lua_isdirectory(lua_State *L) {
|
||||
binding_argcheck(L, 1);
|
||||
|
||||
const char *path = luaL_checkstring(L, 1);
|
||||
|
||||
struct stat st;
|
||||
if (AP::FS().stat(path, &st) != 0) {
|
||||
lua_pushnil(L); /* return nil and ... */
|
||||
lua_pushstring(L, strerror(errno)); /* error message */
|
||||
return 2;
|
||||
}
|
||||
bool ret = (st.st_mode & S_IFMT) == S_IFDIR;
|
||||
lua_pushboolean(L, ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
remove a file
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user