mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
fbd62c7b50
commit
6e86375f9b
25
README.md
25
README.md
@ -56,20 +56,39 @@ int main(){
|
|||||||
VM* vm = new VM();
|
VM* vm = new VM();
|
||||||
|
|
||||||
// Hello world!
|
// Hello world!
|
||||||
vm->exec("print('Hello world!')", "main.py", EXEC_MODE);
|
vm->exec("print('Hello world!')");
|
||||||
|
|
||||||
// Create a list
|
// 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
|
// 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
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
Check this [Cheatsheet](https://reference.pocketpy.dev/python.html)
|
||||||
|
for a quick overview of the supported features.
|
||||||
|
|
||||||
| Name | Example | Supported |
|
| Name | Example | Supported |
|
||||||
| --------------- | ------------------------------- | --------- |
|
| --------------- | ------------------------------- | --------- |
|
||||||
| If Else | `if..else..elif` | YES |
|
| If Else | `if..else..elif` | YES |
|
||||||
|
@ -4,6 +4,9 @@ title: Basic Features
|
|||||||
order: 100
|
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 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.
|
The features marked with `YES` are supported, and the features marked with `NO` are not supported.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user