#include <Python.h>

static PyObject*
really_call_ftw(PyObject* self, PyObject* args)
{
	PyObject* dirname = NULL;

	/* args is a tuple containing the argument list. We could check that
	 * its length is what we expect manually, then extract the items to
	 * our variables, using PyTuple_GetItem(), but this function is
	 * specially intended for parsing function arguments and takes care
	 * of a lot of nice housekeeping for us.
	 */
	PyArg_ParseTuple(args, "O", &dirname);

	/* Note that dirname now holds a BORROWED reference.
	 * For this step, we'll just return that string plus " is the dir".
	 */
	PyObject* returnval = PyString_FromFormat("%s is the dir",
	                                          PyString_AsString(dirname));

	/* returnval is a NEW reference, so we can just return it. Ownership
	 * is passed on.
	 */
	return returnval;
}

static PyMethodDef FtwMethods[] = {
	{"ftw", really_call_ftw, METH_VARARGS, "Traverse a directory structure."},
	{NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC
initftw4()
{
	Py_InitModule("ftw4", FtwMethods);
}
