From d954e74188f8cb7d0bfd834929140c6454d0d398 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 4 Dec 2022 04:13:20 +0800 Subject: [PATCH] up --- src/builtins.h | 26 ++++++++++++++++++++++++++ src/pocketpy.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/builtins.h b/src/builtins.h index 927f16d2..16f05494 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -282,6 +282,32 @@ def open(path, mode='r'): return FileIO(path, mode) )"; +const char* __OS_CODE = R"( +def listdir(path): + assert type(path) is str + return jsonrpc("os.listdir", [path]) + +def mkdir(path): + assert type(path) is str + return jsonrpc("os.mkdir", [path]) + +def rmdir(path): + assert type(path) is str + return jsonrpc("os.rmdir", [path]) + +def remove(path): + assert type(path) is str + return jsonrpc("os.remove", [path]) + +path = object() + +def __path4exists(path): + assert type(path) is str + return jsonrpc("os.path.exists", [path]) +path.exists = __path4exists +del __path4exists +)"; + const char* __RANDOM_CODE = R"( import time as _time diff --git a/src/pocketpy.h b/src/pocketpy.h index 555b33de..a016eecd 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -769,6 +769,7 @@ extern "C" { if(code == nullptr) exit(1); vm->_exec(code, vm->builtins, {}); pkpy_vm_add_module(vm, "random", __RANDOM_CODE); + pkpy_vm_add_module(vm, "os", __OS_CODE); } __EXPORT