From 620e82f0abfb100490487b3c2013a69c03aa39cd Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 12 Aug 2023 16:09:53 +0800 Subject: [PATCH] add `os.system` --- docs/modules/os.md | 4 ++++ src/io.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/docs/modules/os.md b/docs/modules/os.md index c929a660..46bdc3a0 100644 --- a/docs/modules/os.md +++ b/docs/modules/os.md @@ -23,6 +23,10 @@ Returns a list of files and directories in the given path. Removes the file at the given path. +### `os.system(command: str) -> int` + +Executes the given command in the system shell. + ### `os.mkdir(path: str)` Creates a directory at the given path. diff --git a/src/io.cpp b/src/io.cpp index 9b2a59d7..c0251d55 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -113,6 +113,13 @@ void add_module_os(VM* vm){ return vm->None; }); + // system + vm->bind_func<1>(mod, "system", [](VM* vm, ArgsView args){ + std::string cmd = CAST(Str&, args[0]).str(); + int ret = system(cmd.c_str()); + return VAR(ret); + }); + vm->bind_func<1>(mod, "listdir", [](VM* vm, ArgsView args){ std::filesystem::path path(CAST(Str&, args[0]).sv()); std::filesystem::directory_iterator di;