PythonInterpreter.h 877 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef PYTHON_PYTHONINTERPRETER_H
  2. #define PYTHON_PYTHONINTERPRETER_H
  3. #include <boost/noncopyable.hpp>
  4. #include <unordered_set>
  5. #include <boost/shared_ptr.hpp>
  6. #include "Base/Marcos.h"
  7. #include "Python/PythonInit.h"
  8. namespace Egametang {
  9. class PythonInterpreter: private boost::noncopyable
  10. {
  11. private:
  12. PythonInit python;
  13. boost::python::object mainNS;
  14. std::unordered_set<std::string> paths;
  15. std::unordered_set<std::string> modules;
  16. private:
  17. bool GetExecString(const std::string& main_fun, std::string& exec_string);
  18. public:
  19. PythonInterpreter();
  20. void ImportPath(std::string path);
  21. void ImportModule(std::string module);
  22. template <typename T>
  23. void RegisterObjectPtr(std::string name, std::shared_ptr<T> object_ptr)
  24. {
  25. mainNS[name.c_str()] = object_ptr;
  26. }
  27. void Execute(std::string main_fun);
  28. };
  29. } // namespace Egametang
  30. #endif // PYTHON_PYTHONINTERPRETER_H