diff --git a/README.md b/README.md index 7a4b6ec6..0cefa0bf 100644 --- a/README.md +++ b/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_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 | diff --git a/docs/features/basic.md b/docs/features/basic.md index c37aad63..d34c71b7 100644 --- a/docs/features/basic.md +++ b/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.