Advertisement
Guest User

Untitled

a guest
Jan 25th, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. CPyObject Main(PyImport_ImportModule("__main__"));
  2.  
  3. if (!Main)
  4. {
  5.     strError = "failed to import __main__";
  6.     return false;
  7. }
  8.  
  9. CPyObject Globals(PyModule_GetDict(Main), true);
  10.  
  11. if (!Globals)
  12. {
  13.     strError = "failed to create locals and globals";
  14.     return false;
  15. }
  16.  
  17. if (!pExtensionManager->OnScriptLoad(this, strError))
  18. {
  19.     return false;
  20. }
  21.  
  22. // hier findet ihr die Übergabe der globalen/lokalen Variablen
  23. CPyObject Module(PyImport_ImportModuleEx((char*)this->m_strRealName.c_str(), Globals, Globals, NULL));
  24. PyObject *pyErrException = PyErr_Occurred();
  25.  
  26. if (!Module || pyErrException)
  27. {
  28.     if (pyErrException && PyErr_GivenExceptionMatches(pyErrException, PyExc_ImportError))
  29.     {
  30.         strError = "script does not exist";
  31.         return false;
  32.     }
  33.  
  34.     PyErr_Print();
  35.     strError = "failed to load: module couldn't be loaded";
  36.  
  37.     return false;
  38. }
  39.  
  40. PyObject *pyDict = PyModule_GetDict(Module);
  41.  
  42. if (!pyDict)
  43. {
  44.     strError = "failed to resolve __dict__";
  45.     return false;
  46. }
  47.  
  48. // ab hier ist alles sicher geladen
  49. Module.IncRef();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement