PythonEngine.h 683 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef __SCRIPTING__PYTHON_ENGINE_H__
  2. #define __SCRIPTING__PYTHON_ENGINE_H__
  3. #include <pybind11/embed.h>
  4. #include <string>
  5. #include <functional>
  6. #include "../Engine.h"
  7. namespace py = pybind11;
  8. class PythonEngine
  9. {
  10. public:
  11. static PythonEngine& Get();
  12. void Init();
  13. void Shutdown();
  14. void Exec(const std::string& code, Engine& engine);
  15. py::object Call(const std::string& module, const std::string& func, py::args args = {});
  16. // Hot reload scripts for later
  17. void ReloadAllScripts();
  18. private:
  19. PythonEngine() = default;
  20. ~PythonEngine() = default;
  21. py::scoped_interpreter guard_;
  22. bool initialized_ = false;
  23. };
  24. #endif