Extend/Embed Python Method table Dispatcher

Brad Clements bkc at Murkworks.com
Fri Jul 21 10:00:28 EDT 2000


Suggest that you create three functions.

Two "shell" functions that are in the PyMethodDef table, they call the 3rd
function that does the work, passing in an indicator of "who called me".

--
Brad Clements,
bkc at murkworks.com
<heath7952 at my-deja.com> wrote in message news:8l85e1$eti$1 at nnrp1.deja.com...
> Dear All,
>
> I am extending Python with my own C functions. I would like be able to
> share one C function amongst different extended commands. Here's a
> little pseudo example.
>
>
> // standard method table with two commands specified "do_stuff" and
> "do_stuff2" both of which call the same C function.
>
> static PyMethodDef my_methods[] = {
>   {"do_stuff",    (PyCFunction)Python_Embed::fnDoStuff, METH_VARARGS,
> dostuff__doc__   },
>   {"do_stuff2",    (PyCFunction)Python_Embed::fnDoStuff, METH_VARARGS,
> dostuff2__doc__   },
>   {NULL,    NULL}
> };
>
> PyObject* Python_Embed::fnDoStuff(PyObject* self, PyObject* args)
> {
>
>     switch(who called me)
>        case do_stuff:
>           do something
>        break;
>
>        case do_stuff2
>           do something different.
>        break;
>
>
>
> }
>
>
> I looked at args, but I was unable to find anything in the PyObject
> worth extracting for this purpose.
>
> Any help would be greatly appreciated.
>
> Heath.
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.





More information about the Python-list mailing list