BLUELOVETH hace 2 años
padre
commit
6e86375f9b
Se han modificado 2 ficheros con 26 adiciones y 4 borrados
  1. 23 4
      README.md
  2. 3 0
      docs/features/basic.md

+ 23 - 4
README.md

@@ -54,22 +54,41 @@ using namespace pkpy;
 int main(){
     // Create a virtual machine
     VM* vm = new VM();
-    
+
     // Hello world!
-    vm->exec("print('Hello world!')", "main.py", EXEC_MODE);
+    vm->exec("print('Hello world!')");
 
     // Create a list
-    vm->exec("a = [1, 2, 3]", "main.py", EXEC_MODE);
+    vm->exec("a = [1, 2, 3]");
 
     // Eval the sum of the list
-    PyObject* result = vm->exec("sum(a)", "<eval>", EVAL_MODE);
+    PyObject* result = vm->eval("sum(a)");
     std::cout << CAST(int, result);   // 6
+
+    // Bindings
+    vm->bind(vm->_main, "add(a: int, b: int)",
+      [](VM* vm, ArgsView args){
+        int a = CAST(int, args[0]);
+        int b = CAST(int, args[1]);
+        return VAR(a + b);
+      });
+
+    // Call the function
+    PyObject* f_add = vm->_main->attr("add");
+    result = vm->call(f_add, VAR(3), VAR(7));
+    std::cout << CAST(int, result);   // 10
+
+    // Dispose the virtual machine
+    delete vm;
     return 0;
 }
 ```
 
 ## Features
 
+Check this [Cheatsheet](https://reference.pocketpy.dev/python.html)
+for a quick overview of the supported features.
+
 | Name            | Example                         | Supported |
 | --------------- | ------------------------------- | --------- |
 | If Else         | `if..else..elif`                | YES       |

+ 3 - 0
docs/features/basic.md

@@ -4,6 +4,9 @@ title: Basic Features
 order: 100
 ---
 
+Check this [Cheatsheet](https://reference.pocketpy.dev/python.html)
+for a quick overview of the supported features.
+
 The following table shows the basic features of pkpy with respect to [cpython](https://github.com/python/cpython).
 The features marked with `YES` are supported, and the features marked with `NO` are not supported.