Source

pygame / symbian / app / pygame_main.cpp

/** Creates Python interpreter and launches pygame's main script */

#include <sdl.h>
#include <Python.h>

#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2
#include <CSPyInterpreter.h>
#endif

#include "logmanutils.h"

extern "C" struct _inittab _PyGame_Inittab[];

#define NL "\n"

#ifndef PYGAME_MAIN_SCRIPT_PATH
#define PYGAME_MAIN_SCRIPT_PATH "\\data\\pygame\\pygame_main.py"
#define PYGAME_LAUNCHER_PATH    "\\data\\pygame\\launcher\\pygame_launcher.py"
#endif
static const char* gPygameMainScriptPath[2] = {
		PYGAME_MAIN_SCRIPT_PATH,
		PYGAME_LAUNCHER_PATH
		};

int main(int argc, char** argv)
{
	// Execute the main script
#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2
	CSPyInterpreter* interp = CSPyInterpreter::NewInterpreterL();
#else
	SPy_DLC_Init();
	SPy_SetAllocator(SPy_DLC_Alloc, SPy_DLC_Realloc, SPy_DLC_Free, NULL);
#endif
	Py_Initialize();

	// Add built-in pygame modules
#ifdef HAVE_STATIC_MODULES
	PyImport_ExtendInittab(_PyGame_Inittab);
#endif

	LOGMAN_SENDLOG( "Entering interpreter");
#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2
	TInt result = interp->RunScript(1, gPygameMainScriptPath);
#else

	LOGMAN_SENDLOGF("Number of args:%d", argc);
	if(argc > 1){
		gPygameMainScriptPath[1] = argv[1];
	}

	LOGMAN_SENDLOGF8( "Opening file:%s", gPygameMainScriptPath[0] );
	FILE *fp = fopen(gPygameMainScriptPath[0], "r");
	if (!fp) {
		LOGMAN_SENDLOG( "Failed to open main script" );
		return -1;
	}

	// This allows us to retrieve the path of the main script in Python from sys.argv[0]
	PySys_SetArgv(2, (char**)gPygameMainScriptPath);

	int result = PyRun_SimpleFile(fp, gPygameMainScriptPath[0]);
	fclose(fp);
#endif

	LOGMAN_SENDLOGF( "Interpreter result:%d", result )

#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2
	PyEval_RestoreThread(PYTHON_TLS->thread_state);
	Py_Finalize();
	delete interp;
#else
	Py_Finalize();
	SPy_DLC_Fini();
#endif

	SDL_Quit();
	return result;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.