| 279 | } |
| 280 | |
| 281 | int cliLuaListDir(lua_State* L) { |
| 282 | auto path = cliGetString(L, 1); |
| 283 | std::error_code err; |
| 284 | if (!fs::is_directory(path, err)) { |
| 285 | lua_newtable(L); |
| 286 | return 1; |
| 287 | } |
| 288 | lua_newtable(L); |
| 289 | int i = 1; |
| 290 | for (const auto& entry : fs::directory_iterator(path, err)) { |
| 291 | if (err) break; |
| 292 | lua_newtable(L); |
| 293 | auto name = entry.path().filename().string(); |
| 294 | auto fullPath = entry.path().string(); |
| 295 | lua_pushlstring(L, name.c_str(), name.size()); |
| 296 | lua_setfield(L, -2, "name"); |
| 297 | lua_pushlstring(L, fullPath.c_str(), fullPath.size()); |
| 298 | lua_setfield(L, -2, "path"); |
| 299 | lua_pushboolean(L, entry.is_directory()); |
| 300 | lua_setfield(L, -2, "isDir"); |
| 301 | lua_pushboolean(L, entry.is_regular_file()); |
| 302 | lua_setfield(L, -2, "isFile"); |
| 303 | lua_rawseti(L, -2, i++); |
| 304 | } |
| 305 | return 1; |
| 306 | } |
| 307 | |
| 308 | int cliLuaMTime(lua_State* L) { |
| 309 | std::error_code err; |
nothing calls this directly
no test coverage detected