mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
1016 B
1016 B
icon | label | order |
---|---|---|
code | Installation | 100 |
You need to download pocketpy.h
on our GitHub release page.
And #include
it in your project.
https://github.com/blueloveTH/pocketpy/releases/latest
Alternatively, you can install it via vcpkg.io. (Will be available soon)
vcpkg install pocketpy
Compile flags
To compile it with your project, these flags must be set:
--std=c++17
flag must be set- Exception must be enabled
- RTTI is not required
!!!
For maximum performance, we recommend to use clang++
with -O2
flag.
!!!
Example
#include "pocketpy.h"
using namespace pkpy;
int main(){
// Create a virtual machine
VM* vm = new VM(true);
// Hello world!
vm->exec("print('Hello world!')", "main.py", EXEC_MODE);
// Create a list
vm->exec("a = [1, 2, 3]", "main.py", EXEC_MODE);
// Eval the sum of the list
PyObject* result = vm->exec("sum(a)", "<eval>", EVAL_MODE);
std::cout << CAST(int, result); // 6
return 0;
}