[C++-sig] Inserting custom code into pyplusplus output
roman.yakovenko at gmail.com
Thu Jun 15 07:55:13 CEST 2006
On 6/15/06, Niall Douglas <s_sourceforge at nedprod.com> wrote:
> On 13 Jun 2006 at 21:13, Roman Yakovenko wrote:
> > > > mb = module_builder_t( ... _
> > > > FXApp = mb.class_( 'FXApp' )
> > > > FXApp.member_functions( 'init' ).exclude()
> > > > init = """def("init", &FX::FXApp::init,
> > > > &TnFOX::FX_FXApp_Wrapper::default_init_3)"""
> > > > FXApp.add_code( init )
> > > > ...
> > >
> > > Unfortunately, FXApp::init is a required function for all GUI
> > > programs. It also mandatorily takes argc and argv.
> > I think I was not clear. I showed you the way to replace code that would
> > be generated by pyplusplus for FXApp::init member function, with your own code.
> Ah right. I did get that bit, but I didn't see how to custom insert
> some text before the RegisterFXApp() function. For example, if using
> the above trying:
> replacement definition>))
> ... it turns out FXApp.parent is a namespace, and it wouldn't let me
> adopt custom code into it.
> Once again, consulting the source left me pretty clueless :(
I did not write FXApp.parent - this will not work, you already know this.
If you want to insert a code in some specific place, then :
module.body.adopt_creator( code_creators.custom_text_t( ... ), position )
( By default the code creator will be appended to the end of the list )
module is top level, root, main code creator. It derives from compound_t code
creator. So it keeps a list of other code creators, including module_body_t.
If you take a look in debugger on module_t code creator ( mb.code_creator )
you will see something like this:
<precompiled_header_t ... >
<include_t ... >
<module_body_t ...>#<= it generates BOOST_PYTHON_MODULE macro
<class_t ... >
FXApp is not code creator, but declaration. Declarations tree is used
as input to
code creators factory. They are different beast. Am I clear? If you need more
explanation, please ask some specific question, okay?
C++ Python language binding
More information about the Cplusplus-sig