[C++-sig] Inserting custom code into pyplusplus output

Niall Douglas s_sourceforge at nedprod.com
Tue Jun 13 03:53:00 CEST 2006


How do I insert custom code into the BOOST_PYTHON_MODULE() output 
from pyplusplus?


I want:

extern void InitialiseTnFOXPython();

BOOST_PYTHON_MODULE(TnFOX){
    InitialiseTnFOXPython();

    register_enumerations();

    register_FXVec3f_class();

...

I can't see any way from the sources on how to do this :(



Next bit of custom code:

In FXApp::init(), it takes mandatory parameters of void init( int & 
argc, char * * argv, ::FX::FXbool connect ). Obviously, BPL doesn't 
know to match a list of strings to a char **argv, so under pyste I 
inserted the following custom code:

DEFINE_MAKECARRAYITER(FXApp, const FX::FXchar *, getArgv, (), 
c.getArgc())
static void FXApp_init(FXApp &app, int argc, list argv, unsigned char 
connect=TRUE)
{
	int n, size=PyList_Size(argv.ptr());
	static QMemArray<const char *> array;
	array.resize(size+1);
	for(n=0; n<size; n++)
	{
		array[n]=PyString_AsString(PyList_GetItem(argv.ptr(), n));
	}
	array[n]=0;
	app.init(argc, (char **)(array.data()), connect);
}
static void FXApp_init2(FXApp &app, int argc, list argv)
{
	FXApp_init(app, argc, argv);
}

... and then I replaced:

-        .def("init", &FX::FXApp::init, 
&TnFOX::FX_FXApp_Wrapper::default_init_3)
-        .def("init", &TnFOX::FX_FXApp_Wrapper::default_init_2)
+        .def("init", &FXApp_init)
+        .def("init", &FXApp_init2)

-        .def("getArgv", &FX::FXApp::getArgv, 
return_internal_reference< 1 >())
+        .def("getArgv", &FXApp_getArgv)

So can pyplusplus be extended to automatically generate this kind of 
accessor code, if not how can I insert this custom code via 
pyplusplus?

(We are very close to a working TnFOX python bindings. Yay!)

Cheers,
Niall






More information about the Cplusplus-sig mailing list