This commit is contained in:
BLUELOVETH 2023-08-25 13:36:12 +08:00
parent fbd62c7b50
commit 6e86375f9b
2 changed files with 26 additions and 4 deletions

View File

@ -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 |

View File

@ -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.