update os

This commit is contained in:
blueloveTH 2024-04-14 14:19:08 +08:00
parent c5e055e1a8
commit 5eaef2c900
2 changed files with 29 additions and 0 deletions

View File

@ -43,6 +43,18 @@ Check if the given path exists.
Returns the basename of the given path. Returns the basename of the given path.
### `os.path.isdir(path: str)`
Check if the given path is a directory.
### `os.path.isfile(path: str)`
Check if the given path is a file.
### `os.path.abspath(path: str)`
Returns the absolute path of the given path.
## Other functions ## Other functions

View File

@ -226,6 +226,23 @@ void add_module_os(VM* vm){
std::filesystem::path path(CAST(Str&, args[0]).sv()); std::filesystem::path path(CAST(Str&, args[0]).sv());
return VAR(path.filename().string()); return VAR(path.filename().string());
}); });
vm->bind_func<1>(path_obj, "isdir", [](VM* vm, ArgsView args){
std::filesystem::path path(CAST(Str&, args[0]).sv());
bool isdir = std::filesystem::is_directory(path);
return VAR(isdir);
});
vm->bind_func<1>(path_obj, "isfile", [](VM* vm, ArgsView args){
std::filesystem::path path(CAST(Str&, args[0]).sv());
bool isfile = std::filesystem::is_regular_file(path);
return VAR(isfile);
});
vm->bind_func<1>(path_obj, "abspath", [](VM* vm, ArgsView args){
std::filesystem::path path(CAST(Str&, args[0]).sv());
return VAR(std::filesystem::absolute(path).string());
});
} }
#else #else