| 328 | //============================================================================// |
| 329 | |
| 330 | int LuaVFS::DirList(lua_State* L) { |
| 331 | const char* path = luaL_checkstring(L, 1); |
| 332 | std::string modes = luaL_optstring(L, 2, GetReadFilter(path, L)); |
| 333 | modes = BzVFS::allowModes(modes, L2ES(L)->vfsModes->readAllowed); |
| 334 | |
| 335 | const bool recursive = lua_isboolean(L, 3) && lua_tobool(L, 3); |
| 336 | |
| 337 | std::vector<std::string> files; |
| 338 | std::vector<std::string> dirs; |
| 339 | if (!bzVFS.dirList(path, modes, recursive, dirs, files)) { |
| 340 | lua_pushnil(L); |
| 341 | return 1; |
| 342 | } |
| 343 | |
| 344 | lua_createtable(L, files.size(), 0); |
| 345 | for (size_t i = 0; i < files.size(); i++) { |
| 346 | const std::string& fpath = files[i]; |
| 347 | lua_pushinteger(L, i + 1); |
| 348 | lua_pushstdstring(L, fpath); |
| 349 | lua_rawset(L, -3); |
| 350 | } |
| 351 | |
| 352 | lua_createtable(L, dirs.size(), 0); |
| 353 | for (size_t i = 0; i < dirs.size(); i++) { |
| 354 | const std::string& dpath = dirs[i]; |
| 355 | lua_pushinteger(L, i + 1); |
| 356 | lua_pushstdstring(L, dpath); |
| 357 | lua_rawset(L, -3); |
| 358 | } |
| 359 | |
| 360 | return 2; |
| 361 | } |
| 362 | |
| 363 | |
| 364 | //============================================================================// |
nothing calls this directly
no test coverage detected