MCPcopy Create free account
hub / github.com/DFHack/dfhack / filesystem_listdir_recursive

Function filesystem_listdir_recursive

library/LuaApi.cpp:3374–3407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3372}
3373
3374static int filesystem_listdir_recursive(lua_State *L)
3375{
3376 luaL_checktype(L,1,LUA_TSTRING);
3377 string dir=lua_tostring(L,1);
3378 int depth = 10;
3379 if (lua_gettop(L) >= 2 && !lua_isnil(L, 2))
3380 depth = luaL_checkint(L, 2);
3381 bool include_prefix = true;
3382 if (lua_gettop(L) >= 3 && !lua_isnil(L, 3))
3383 include_prefix = lua_toboolean(L, 3);
3384 std::map<std::filesystem::path, bool> files;
3385 int err = DFHack::Filesystem::listdir_recursive(dir, files, depth, include_prefix);
3386 if (err != 0 && err != -1) {
3387 lua_pushnil(L);
3388 lua_pushstring(L, strerror(err));
3389 lua_pushinteger(L, err);
3390 return 3;
3391 }
3392 lua_newtable(L);
3393 int i = 1;
3394 for (auto it = files.begin(); it != files.end(); ++it)
3395 {
3396 lua_pushinteger(L, i++);
3397 lua_newtable(L);
3398 lua_pushstring(L, "path");
3399 lua_pushstring(L, Filesystem::as_string(it->first).c_str());
3400 lua_settable(L, -3);
3401 lua_pushstring(L, "isdir");
3402 lua_pushboolean(L, it->second);
3403 lua_settable(L, -3);
3404 lua_settable(L, -3);
3405 }
3406 return 1;
3407}
3408
3409static const luaL_Reg dfhack_filesystem_funcs[] = {
3410 {"listdir", filesystem_listdir},

Callers

nothing calls this directly

Calls 12

luaL_checktypeFunction · 0.85
lua_gettopFunction · 0.85
lua_tobooleanFunction · 0.85
lua_pushnilFunction · 0.85
lua_pushstringFunction · 0.85
lua_pushintegerFunction · 0.85
as_stringFunction · 0.85
lua_settableFunction · 0.85
lua_pushbooleanFunction · 0.85
c_strMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected