Skip to content

Commit

Permalink
support directory_options
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed May 10, 2024
1 parent 1518543 commit 4fef6bf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions binding/lua_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,9 @@ namespace bee::lua_filesystem {
};
luaL_setfuncs(L, mt, 0);
}
static lua::cxx::status constructor(lua_State* L, const fs::path& path) {
static lua::cxx::status constructor(lua_State* L, const fs::path& path, fs::directory_options options) {
std::error_code ec;
lua::newudata<T>(L, path, ec);
lua::newudata<T>(L, path, options, ec);
if (ec) {
return pusherror(L, "directory_iterator::directory_iterator", ec, path);
}
Expand All @@ -865,7 +865,8 @@ namespace bee::lua_filesystem {

static lua::cxx::status pairs(lua_State* L) {
path_ref p(L, 1);
if (auto s = pairs_directory<fs::directory_iterator>::constructor(L, p); !s) {
auto options = lua::optinteger<fs::directory_options, fs::directory_options::none>(L, 2);
if (auto s = pairs_directory<fs::directory_iterator>::constructor(L, p, options); !s) {
return s;
}
lua_pushnil(L);
Expand All @@ -876,7 +877,8 @@ namespace bee::lua_filesystem {

static lua::cxx::status pairs_r(lua_State* L) {
path_ref p(L, 1);
if (auto s = pairs_directory<fs::recursive_directory_iterator>::constructor(L, p); !s) {
auto options = lua::optinteger<fs::directory_options, fs::directory_options::none>(L, 2);
if (auto s = pairs_directory<fs::recursive_directory_iterator>::constructor(L, p, options); !s) {
return s;
}
lua_pushnil(L);
Expand Down Expand Up @@ -996,6 +998,12 @@ namespace bee::lua_filesystem {
DEF_ENUM(perm_options, remove);
DEF_ENUM(perm_options, nofollow);
lua_setfield(L, -2, "perm_options");

lua_createtable(L, 0, 3);
DEF_ENUM(directory_options, none);
DEF_ENUM(directory_options, follow_directory_symlink);
DEF_ENUM(directory_options, skip_permission_denied);
lua_setfield(L, -2, "directory_options");
return 1;
}
}
Expand Down

0 comments on commit 4fef6bf

Please sign in to comment.