[C++-sig] Project architecture and Py++

Benoit Leveau benoit-l at moving-picture.com
Fri Jul 16 10:30:09 CEST 2010


Pentix wrote:
> Hi,
> 
> I’d like to use Python in the following way:
> 
> 1) create a library (pyd) with some interfaces of the main program taken
> outside; generate then its code with py++
> 2) create a set of scripts, that use this library
> 3) execute these scripts with boost::python from the main program
> 
> Unwillingness to carry out any manual corrections of the generated code is
> an important part of the solution. The code is being generated
> authomatically, and only the script and the imported header are to be
> corrected in case of any problem. It is motivated by the fact, that
> the program is developing dynamically and it is better to see and solve
> immedeately the emerging discrepancies.
> 
> Thus, the main task of implementation phase been solved already, but there
> arose the following problem: there appeared a desire to transfer
> into python our objects (from those being exposed). But all wrappers are
> being generated into the library from the point 1, and are in the
> cpp files. 
> 
> I’m ready to make the dependance of the main module on the library. But how
> to get the wrappers, if it is undesirable to correct the generated code
> manually?

Hi,

Manually fixing the generated code is indeed a bad idea.

You should take a look at the code injection feature of py++.

What you can do is having your "binding generator" detecting some
custom files and then injecting the code in the wrappers.
- you define a "custom code" folder,
- whenever your generator detects a "MyClass_injection.cpp" file,
then it will inject the code of this file into the wrapper of 'MyClass',
>>> cls.add_wrapper_code( custom_code )

This is the basic approach, you may need to inject declaration code, registration code, some code at the
module level and not the class level, handle templates, etc. but once you get the basic system in place,
you can add more features as the need arise.

This way, you don't have to change your original headers nor the generated code directly.

Hope that helps,
Benoit


More information about the Cplusplus-sig mailing list