This commit is contained in:
blueloveTH 2022-12-04 04:13:20 +08:00
parent e5c96c2732
commit d954e74188
2 changed files with 27 additions and 0 deletions

View File

@ -282,6 +282,32 @@ def open(path, mode='r'):
return FileIO(path, mode) 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"( const char* __RANDOM_CODE = R"(
import time as _time import time as _time

View File

@ -769,6 +769,7 @@ extern "C" {
if(code == nullptr) exit(1); if(code == nullptr) exit(1);
vm->_exec(code, vm->builtins, {}); vm->_exec(code, vm->builtins, {});
pkpy_vm_add_module(vm, "random", __RANDOM_CODE); pkpy_vm_add_module(vm, "random", __RANDOM_CODE);
pkpy_vm_add_module(vm, "os", __OS_CODE);
} }
__EXPORT __EXPORT