blueloveTH há 2 anos atrás
pai
commit
a97149778a

+ 1 - 1
README.md

@@ -64,7 +64,7 @@ Check [C-API](https://pocketpy.dev/c-api/vm/) for references. For further custom
 
 int main(){
     // Create a virtual machine
-    auto vm = pkpy_new_vm(true);
+    auto vm = pkpy_new_vm();
     
     // Hello world!
     pkpy_vm_exec(vm, "print('Hello world!')");

+ 1 - 1
README_zh.md

@@ -54,7 +54,7 @@ PocketPy是一个轻量级的Python解释器,为嵌入至游戏引擎而设计
 
 int main(){
     // 创建一个虚拟机
-    auto vm = pkpy_new_vm(true);
+    auto vm = pkpy_new_vm();
     
     // Hello world!
     pkpy_vm_exec(vm, "print('Hello world!')");

+ 1 - 1
docs/plugins/c.md

@@ -15,7 +15,7 @@ https://github.com/blueloveTH/pocketpy/releases/latest
 
 int main(){
     // Create a virtual machine
-    auto vm = pkpy_new_vm(true);
+    auto vm = pkpy_new_vm();
     
     // Hello world!
     pkpy_vm_exec(vm, "print('Hello world!')");

+ 0 - 0
docs/quick-start/03_attr.md → docs/quick-start/attr.md


+ 2 - 2
docs/quick-start/05_bind.md → docs/quick-start/bind.md

@@ -19,7 +19,7 @@ Native functions do not support keyword arguments.
 
 !!!
 
-PkPy uses a universal C function pointer for native functions:
+pkpy uses a universal C function pointer for native functions:
 
 ```cpp
 typedef PyObject* (*NativeFuncC)(VM*, ArgsView);
@@ -34,7 +34,7 @@ The return value is a `PyObject*`, which should not be `nullptr`. If there is no
 This is an example of binding the `input()` function to the `builtins` module.
 
 ```cpp
-VM* vm = pkpy_new_vm(true);
+VM* vm = pkpy_new_vm();
 vm->bind_builtin_func<0>("input", [](VM* vm, ArgsView args){
     static std::string line;
     std::getline(std::cin, line);

+ 0 - 0
docs/quick-start/04_call.md → docs/quick-start/call.md


+ 0 - 0
docs/quick-start/01_installation.md → docs/quick-start/installation.md


+ 0 - 0
docs/quick-start/02_interop.md → docs/quick-start/interop.md


+ 16 - 0
docs/quick-start/overview.md

@@ -0,0 +1,16 @@
+---
+icon: code
+label: 'Overview'
+order: 95
+---
+
+pkpy's C++ interfaces are organized in an object-oriented way.
+All classes are located in `pkpy` namespace.
+
+The most important class is the `VM` class. A `VM` instance is a python virtual machine which holds all necessary runtime states, including callstacks, modules, variables, etc.
+
+You need to use the C++ `new` operator to create a `VM` instance.
+
+```cpp
+VM* vm = new VM();
+```

+ 0 - 0
docs/quick-start/06_wrap.md → docs/quick-start/wrap.md


+ 1 - 1
src/main.cpp

@@ -6,7 +6,7 @@
 #ifndef __EMSCRIPTEN__
 
 int main(int argc, char** argv){
-    pkpy::VM* vm = pkpy_new_vm(true, true);
+    pkpy::VM* vm = pkpy_new_vm();
     vm->bind_builtin_func<0>("input", [](pkpy::VM* vm, pkpy::ArgsView args){
         return VAR(pkpy::getline());
     });

+ 1 - 1
src/pocketpy.h

@@ -973,7 +973,7 @@ extern "C" {
 
     __EXPORT
     /// Create a virtual machine.
-    pkpy::VM* pkpy_new_vm(bool use_stdio, bool enable_os){
+    pkpy::VM* pkpy_new_vm(bool use_stdio=true, bool enable_os=true){
         return PKPY_ALLOCATE(pkpy::VM, use_stdio, enable_os);
     }
 

+ 0 - 25
src/test.cpp

@@ -1,25 +0,0 @@
-#include "cffi.h"
-#include "pocketpy.h"
-
-using namespace pkpy;
-
-float* f(int* a){
-    *a = 100;
-    return new float(3.5f);
-}
-
-int main(){
-    VM* vm = pkpy_new_vm(true);
-    vm->bind_builtin_func<1>("f", NativeProxyFunc(&f));
-
-    pkpy_vm_exec(vm, R"(
-from c import *
-p = cast(malloc(4), "int*")
-ret = f(p)
-print(p.get())          # 100
-print(ret, ret.get())   # 3.5
-)");
-
-    pkpy_delete(vm);
-    return 0;
-}

+ 1 - 1
src/vm.h

@@ -106,7 +106,7 @@ public:
 
     const bool enable_os;
 
-    VM(bool use_stdio, bool enable_os) : heap(this), enable_os(enable_os) {
+    VM(bool use_stdio=true, bool enable_os=true) : heap(this), enable_os(enable_os) {
         this->vm = this;
         this->_stdout = use_stdio ? &std::cout : &_stdout_buffer;
         this->_stderr = use_stdio ? &std::cerr : &_stderr_buffer;

+ 1 - 1
web/index.js

@@ -113,7 +113,7 @@ var Module = {
       term.write(text + "\r\n");
     },
     'onRuntimeInitialized': function(text) {
-      var vm = Module.ccall('pkpy_new_vm', 'number', ['boolean'], [true]);
+      var vm = Module.ccall('pkpy_new_vm', 'number', [], []);
       repl = Module.ccall('pkpy_new_repl', 'number', ['number'], [vm]);
       term.write(need_more_lines ? "... " : ">>> ");
     },