Skip to content

Commit 014f545

Browse files
authored
Merge pull request #63 from Paliak/expose-remove_all
Expose std::filesystem::remove_all functionality to lua side as an argument for RemoveDir
2 parents 4fb2709 + daae40d commit 014f545

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ui_api.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,11 +1552,22 @@ static int l_RemoveDir(lua_State* L)
15521552
{
15531553
ui_main_c* ui = GetUIPtr(L);
15541554
int n = lua_gettop(L);
1555-
ui->LAssert(L, n >= 1, "Usage: l_RemoveDir(path)");
1555+
ui->LAssert(L, n >= 1, "Usage: l_RemoveDir(path, recurse)");
15561556
ui->LAssert(L, lua_isstring(L, 1), "l_RemoveDir() argument 1: expected string, got %s", luaL_typename(L, 1));
1557+
15571558
std::filesystem::path path(lua_tostring(L, 1));
1559+
bool recursive = false;
1560+
1561+
if (n > 1) {
1562+
ui->LAssert(L, lua_isboolean(L, 2), "l_RemoveDir() argument 2: expected boolean, got %s", luaL_typename(L, 2));
1563+
recursive = lua_toboolean(L, 2);
1564+
}
1565+
15581566
std::error_code ec;
1559-
if (!is_directory(path, ec) || ec || !remove(path, ec) || ec) {
1567+
if (!is_directory(path, ec) || ec
1568+
|| (recursive && !remove_all(path, ec)) || ec
1569+
|| (!recursive && !remove(path, ec)) || ec)
1570+
{
15601571
lua_pushnil(L);
15611572
lua_pushstring(L, strerror(ec.value()));
15621573
return 2;

0 commit comments

Comments
 (0)