MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / lua_dirlist

Function lua_dirlist

libraries/AP_Scripting/lua_bindings.cpp:857–883  ·  view source on GitHub ↗

directory listing, return table of files in a directory */

Source from the content-addressed store, hash-verified

855 directory listing, return table of files in a directory
856 */
857int lua_dirlist(lua_State *L) {
858 binding_argcheck(L, 1);
859
860 struct dirent *entry;
861 int i;
862 const char *path = luaL_checkstring(L, 1);
863
864 /* open directory */
865 auto dir = AP::FS().opendir(path);
866 if (dir == nullptr) { /* error opening the directory? */
867 lua_pushnil(L); /* return nil and ... */
868 lua_pushstring(L, strerror(errno)); /* error message */
869 return 2; /* number of results */
870 }
871
872 /* create result table */
873 lua_newtable(L);
874 i = 1;
875 while ((entry = AP::FS().readdir(dir)) != nullptr) {
876 lua_pushnumber(L, i++); /* push key */
877 lua_pushstring(L, entry->d_name); /* push value */
878 lua_settable(L, -3);
879 }
880
881 AP::FS().closedir(dir);
882 return 1; /* table is already on top */
883}
884
885/*
886 remove a file

Callers

nothing calls this directly

Calls 8

lua_pushnilFunction · 0.85
lua_pushstringFunction · 0.85
strerrorFunction · 0.85
lua_pushnumberFunction · 0.85
lua_settableFunction · 0.85
opendirMethod · 0.45
readdirMethod · 0.45
closedirMethod · 0.45

Tested by

no test coverage detected