From 46b1b1b900e6a25c084228a4c5da06dc3de32ff2 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Fri, 28 Apr 2023 13:54:27 +0800 Subject: [PATCH] ... --- docs/modules/os.md | 4 ++++ src/io.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/docs/modules/os.md b/docs/modules/os.md index b6ac9455..c929a660 100644 --- a/docs/modules/os.md +++ b/docs/modules/os.md @@ -38,3 +38,7 @@ Joins the given paths together. ### `os.path.exists(path: str)` Check if the given path exists. + +### `os.path.basename(path: str)` + +Returns the basename of the given path. \ No newline at end of file diff --git a/src/io.h b/src/io.h index 4ce76259..2ae87595 100644 --- a/src/io.h +++ b/src/io.h @@ -169,6 +169,11 @@ inline void add_module_os(VM* vm){ bool exists = std::filesystem::exists(path); return VAR(exists); }); + + vm->bind_func<1>(path_obj, "basename", [](VM* vm, ArgsView args){ + std::filesystem::path path(CAST(Str&, args[0]).sv()); + return VAR(path.filename().string()); + }); } } // namespace pkpy