Help needed for gratuitous kludge

Adrian Eyre a.eyre at optichrome.com
Fri Oct 8 08:59:24 EDT 1999


I'm trying to create an extension module which exports classes
with C methods.

Consider the following C++ code (compiled to a_module.pyd):

static PyObject* a_method(PyObject* self, PyObject* args)
{
    // Code not important
}

extern "C" void __declspec(dllexport) inita_module()
{
    PyObject* a_tuple = PyTuple_New(0);
    PyObject* a_dict = PyDict_New();
    PyObject* a_string = PyString_FromString("MyClass");
    PyObject* a_class = PyClass_New(a_tuple, a_dict, a_string);

    PyObject* mod = PyImportAdd_Module("a_module");
    PyObject* dict = PyModule_GetDict(mod);
    PyDict_SetItemString(dict, "MyClass", a_class);
}

How can I bind 'a_method' to be an instance method of 'MyClass', so
that the self parameter is passed to it. 

I don't care how hacky the solution is. Even if the instance has to
be passed through 'args'.

It must be possible (preferably without have to use an extension type.)
    
--------------------------------------------
Adrian Eyre <mailto:a.eyre at optichrome.com>
Optichrome Computer Solutions Ltd
Maybury Road, Woking, Surrey, GU21 5HX, UK
Tel: +44 1483 740 233  Fax: +44 1483 760 644
http://www.optichrome.com 
--------------------------------------------





More information about the Python-list mailing list