title: When writing a python extension in C, how does one pass a python function in to a C function?
body: <p>First off, apologies for the confusing title. </p>
  
  <p>What I am trying to achieve is the following: Suppose I have some function <code>foo</code> which takes a function and an integer as input. e.g. </p>
  
  <pre><code>int foo(int(*func)(), int i) {
      int n = func() + i;
      return n;
  }
  </code></pre>
  
  <p>Now, I'd like to wrap this function in a python extension module. So I start writing my interface:</p>
  
  <pre><code>#include &lt;Python.h&gt;
  
  extern "C" {
      static PyObject* foo(PyObject* self, PyObject* args);
  }
  
  static PyMethodDef myMethods[] = {
      {"foo", foo, METH_VARARGS, "Runs foo"},
      {NULL, NULL, 0, NULL}
  }
  
  // Define the module
  static struct PyModuleDef myModule = {
      PyModuleDef_HEAD_INIT,
      "myModule",
      "A Module",
      -1,
      myMethods
  };
  
  // Initialize the module
  PyMODINIT_FUNC PyInit_BSPy(void) {
      return PyModule_Create(&amp;myModule);
  }
  
  //Include the function
  static PyObject* foo(PyObject* self, PyObject* args){
      // Declare variable/function pointer
      int(*bar)(void);
      unsigned int n;
  
      // Parse the input tuple
      if (!PyArg_ParseTuple(args, ..., &amp;bar, &amp;n)) {
          return NULL;
      }
  }
  </code></pre>
  
  <p>Now, when it comes time to parse the input tuple, I get confused, as I'm not really sure how to parse it. The idea is rather simple: I need to be able to call <code>foo(bar(), n)</code> in python. But I could use some help on how to realize this.</p>