io.h 589 B

1234567891011121314151617181920212223242526272829303132
  1. #pragma once
  2. #include "cffi.h"
  3. namespace pkpy{
  4. Bytes _default_import_handler(const Str& name);
  5. void add_module_os(VM* vm);
  6. void add_module_io(VM* vm);
  7. }
  8. #if PK_ENABLE_OS
  9. #include <filesystem>
  10. #include <cstdio>
  11. namespace pkpy{
  12. struct FileIO {
  13. PY_CLASS(FileIO, io, FileIO)
  14. Str file;
  15. Str mode;
  16. FILE* fp;
  17. bool is_text() const { return mode != "rb" && mode != "wb" && mode != "ab"; }
  18. FileIO(VM* vm, std::string file, std::string mode);
  19. void close();
  20. static void _register(VM* vm, PyObject* mod, PyObject* type);
  21. };
  22. } // namespace pkpy
  23. #endif