Source

pygamekit / standalone.cpp

Full commit

#include "Python.h"
#include "string.h"

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initgamekit();
PyMODINIT_FUNC initmathutils();
PyMODINIT_FUNC init_py2d();
#else
PyMODINIT_FUNC PyInit_gamekit(void);
PyMODINIT_FUNC PyInit_mathutils(void);
PyMODINIT_FUNC PyInit__py2d();
#endif

#include "standalone.py.h"

int main(int argc, char *argv[]){
  
  Py_SetProgramName(argv[0]);

  Py_Initialize();
  #if PY_MAJOR_VERSION < 3
    init_py2d();
    initmathutils();
    initgamekit();
  #else
    PyInit__py2d();
    PyInit_mathutils(void);
    PyInit_gamekit(void);
  #endif

  if(argc>2 && !strcmp(argv[1],"--custom-script")){
    PySys_SetArgvEx(argc-2, argv+2, 0);
    PyRun_AnyFile(fopen(argv[2],"r"),argv[2]);
  }else{
    PySys_SetArgvEx(argc, argv, 0);
  
    standalone_py[standalone_py_len-1] = '\0'; // Replace last \n with \0
    PyRun_SimpleString((char *)standalone_py);
  }

//   Py_Finalize();  // FIXME: This crashes. Try using cython's refnanny.
  return 0;
}