Making a C extension to Python that requires another extension -


I have some Python functions that I use to make Pygame easier with game development. I found them in my python-path in a file named helper.py, so I can import them from any game. I thought of this as a practice to learn about the Python extension to convert this module into C. My first problem is that I need to use the function from Pygame, and I'm not sure that this is possible. Pygame installs some header files, but they are not the C version of Python Functions. Maybe I'm missing something

How do I solve it? As an alternative solution, the function currently accepts a function parameter and calls it, but this is not the ideal solution.

By using Windows XP, Python 2.6 and Pygame 1.9.1.

  / * sys.modules get dictionary * / PyObject * sysmodules PyImport_GetModuleDict (); PyObject * pygame_module; If (PyMapping_HasKeyString (sysmodules, "pygame")) {pygame_module = PyMapping_GetItemString (sysmodules, "pygame"); } Other {PyObject * initresult; Pygame_module = PyImport_ImportModule ("pygame"); If (! Pygame_module) {/ * insert error handling here! And exit this function * /} initresult = PyObject_CallMethod (pygame_module, "init", NULL); If (! Initresult) {/ * more error handling & amp; C * /} Py_DECREF (initresult); } / * Use PyObject_CallMethod (pygame_module, ...) in your heart's content * / / * and, in the end, when done, forget, before you exit: * / Py_DECREF (pygame_module);  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -