pocketpy_c.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef POCKETPY_C_H
  2. #define POCKETPY_C_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stdbool.h>
  7. #include <stdint.h>
  8. typedef struct pkpy_vm_handle* pkpy_vm;
  9. //we mostly follow the lua api for these bindings
  10. //the key difference being most methods return a bool, true if it succeeded
  11. //false if it did not
  12. //if a method returns false call this next method to check the error and clear it
  13. //if this method returns false it means that no error was set, and no action is taken
  14. //if it returns true it means there was an error and it was cleared, it will provide a string summary of the error in the message parameter (if it is not NULL)
  15. //NOTE : you need to free the message that is passed back after you are done using it
  16. //or else pass in null as message, and it will just print the message to stderr
  17. bool pkpy_clear_error(pkpy_vm, const char** message);
  18. pkpy_vm pkpy_vm_create(bool use_stdio, bool enable_os);
  19. bool pkpy_vm_exec(pkpy_vm vm_handle, const char* source);
  20. void pkpy_vm_destroy(pkpy_vm vm);
  21. typedef int (*pkpy_function)(pkpy_vm);
  22. bool pkpy_push_function(pkpy_vm, pkpy_function);
  23. bool pkpy_push_int(pkpy_vm, int);
  24. bool pkpy_push_float(pkpy_vm, double);
  25. bool pkpy_set_global(pkpy_vm, const char* name);
  26. bool pkpy_get_global(pkpy_vm vm_handle, const char* name);
  27. //first push callable you want to call
  28. //then push the arguments to send
  29. //argc is the number of arguments that was pushed (not counting the callable)
  30. bool pkpy_call(pkpy_vm vm_handle, int argc);
  31. //first push the object the method belongs to (self)
  32. //then push the callable you want to call
  33. //then push the the argments
  34. //argc is the number of arguments that was pushed (not counting the callable or self)
  35. bool pkpy_call_method(pkpy_vm vm_handle, int argc);
  36. //we will break with the lua api here
  37. //lua uses 1 as the index to the first pushed element for all of these functions
  38. //but we will start counting at zero to match python
  39. //we will allow negative numbers to count backwards from the top
  40. bool pkpy_to_int(pkpy_vm vm_handle, int index, int* ret);
  41. #ifdef __cplusplus
  42. }
  43. #endif
  44. #endif