This is a simple example from the python documentation (http://docs.python.org/extending/extending.html):
static PyObject *
spam_system(PyObject *self, PyObject *args)
{
const char *command;
int sts;
if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
sts = system(command);
return Py_BuildValue("i", sts);
}
If I want to pass an additional boolean parameter to the function - what's the "correct" way to do it?
There doesn't seem to be a bool option to pass to PyArg_ParseTuple(). So I thought of the following:
- read an integer and just use the value (as bool is a subclass of int)
- call PyBool_FromLong() on an integer
- read and object and call PyBool_Check() to verify it is a bool
- maybe there's a way to get any type of variable and get its truth value (i.e an empty array will is falsy etc.) which is what python function usually do.
Any of these preferable? Other options?