main.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "pocketpy.h"
  4. char* read_file(const char* path) {
  5. FILE* file = fopen(path, "r");
  6. if(file == NULL) {
  7. printf("Error: file not found\n");
  8. return NULL;
  9. }
  10. fseek(file, 0, SEEK_END);
  11. long size = ftell(file);
  12. fseek(file, 0, SEEK_SET);
  13. char* buffer = malloc(size + 1);
  14. fread(buffer, 1, size, file);
  15. buffer[size] = 0;
  16. return buffer;
  17. }
  18. int main(int argc, char** argv) {
  19. #if _WIN32
  20. SetConsoleCP(CP_UTF8);
  21. SetConsoleOutputCP(CP_UTF8);
  22. #endif
  23. py_initialize();
  24. const char* source = "1 < 2";
  25. py_Ref r0 = py_reg(0);
  26. if(py_eval(source, r0)){
  27. py_Error* err = py_lasterror();
  28. py_Error__print(err);
  29. }else{
  30. // handle the result
  31. bool _L0 = py_tobool(r0);
  32. printf("%d\n", _L0);
  33. }
  34. py_finalize();
  35. return 0;
  36. // if(argc != 2) goto __HELP;
  37. // char* source = read_file(argv[1]);
  38. // py_initialize();
  39. // if(py_exec(source)){
  40. // py_Error* err = py_getlasterror();
  41. // py_Error__print(err);
  42. // }
  43. // py_finalize();
  44. // free(source);
  45. // __HELP:
  46. // printf("Usage: pocketpy [filename]\n");
  47. // return 0;
  48. }