Przeglądaj źródła

add `os.system`

blueloveTH 2 lat temu
rodzic
commit
620e82f0ab
2 zmienionych plików z 11 dodań i 0 usunięć
  1. 4 0
      docs/modules/os.md
  2. 7 0
      src/io.cpp

+ 4 - 0
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.
 Removes the file at the given path.
 
 
+### `os.system(command: str) -> int`
+
+Executes the given command in the system shell.
+
 ### `os.mkdir(path: str)`
 ### `os.mkdir(path: str)`
 
 
 Creates a directory at the given path.
 Creates a directory at the given path.

+ 7 - 0
src/io.cpp

@@ -113,6 +113,13 @@ void add_module_os(VM* vm){
         return vm->None;
         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){
     vm->bind_func<1>(mod, "listdir", [](VM* vm, ArgsView args){
         std::filesystem::path path(CAST(Str&, args[0]).sv());
         std::filesystem::path path(CAST(Str&, args[0]).sv());
         std::filesystem::directory_iterator di;
         std::filesystem::directory_iterator di;