multi_vm.c 664 B

1234567891011121314151617181920212223242526272829303132
  1. #include "pocketpy.h"
  2. int main()
  3. {
  4. py_initialize();
  5. bool ok = py_exec("print('Hello world from VM0!')", "<string1>", EXEC_MODE, NULL);
  6. if(!ok){
  7. py_printexc();
  8. return 1;
  9. }
  10. //This line will cause assert error in Debug build and crash (exception) in Release build
  11. py_switchvm(1);
  12. ok = py_exec("print('Hello world from VM1!')", "<string2>", EXEC_MODE, NULL);
  13. if(!ok){
  14. py_printexc();
  15. return 1;
  16. }
  17. py_switchvm(0);
  18. ok = py_exec("print('Hello world from VM0 again!')", "<string3>", EXEC_MODE, NULL);
  19. if(!ok){
  20. py_printexc();
  21. return 1;
  22. }
  23. py_finalize();
  24. return 0;
  25. }