Răsfoiți Sursa

update `os`

blueloveTH 1 an în urmă
părinte
comite
5eaef2c900
2 a modificat fișierele cu 29 adăugiri și 0 ștergeri
  1. 12 0
      docs/modules/os.md
  2. 17 0
      src/io.cpp

+ 12 - 0
docs/modules/os.md

@@ -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
 
 

+ 17 - 0
src/io.cpp

@@ -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