Source

Numpy Toy Box / convsrc / convsrcmodule.c.src

/* -*- c -*- */
#include <Python.h>

static PyObject *
fact(PyObject *self, PyObject *args)
{
  int n;
  int i;
  int ret=1;
 
  if (!PyArg_ParseTuple(args, "i", &n))
    return NULL;
 
  for (i=n; i>0; i--) ret *= i;
 
  return Py_BuildValue("i", ret);
}

static PyObject *
hello(PyObject *self, PyObject *args)
{
  printf("Hello World!!\n");
  Py_RETURN_NONE;
}

static PyObject *
goodbye(PyObject *self, PyObject *args)
{
  printf("Goodbye!!\n");
  Py_RETURN_NONE;
}

static PyObject *
combination(PyObject *self, PyObject *args)
{
/**begin repeat
   #b=(1)*3, (2)*3, (3)*3#
   #a=(1, 2, 3)*3#
*/
  printf("combination a=@a@ b=@b@\n");
/**end repeat**/
  Py_RETURN_NONE;
}

static char convsrc_doc[] = "C extention module example\n";

static PyMethodDef methods[] = {
/**begin repeat
   #func=fact, hello, goodbye, combination#
*/
  {"@func@", (PyCFunction)@func@, METH_VARARGS, "docstring of @func@.\n"},
/**end repeat**/
  {NULL, NULL}
};

#ifndef PyMODINIT_FUNC	/* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC
initconvsrc(void)
{
  Py_InitModule3("convsrc", methods, convsrc_doc);
}