1
0

5_python_scripting.cpp 542 B

1234567891011121314151617181920212223242526
  1. /**
  2. * This example demonstrate the use of PocketPy as a scripting language.
  3. * It creates a virtual machine and execute a python script.
  4. */
  5. #include "pocketpy.h"
  6. using namespace pkpy;
  7. int main(){
  8. // Create a virtual machine
  9. VM* vm = new VM();
  10. // Print "hello world" to the console
  11. vm->exec("print('hello world')"); // hello world
  12. // List comprehension
  13. vm->exec("l = [i*i for i in range(1, 6)]");
  14. vm->exec("print(l)"); // [1, 4, 9, 16, 25]
  15. // Dispose the virtual machine
  16. delete vm;
  17. return 0;
  18. }