[C++-sig] Re: Exposing C++ objects to Python at runtime

Jonathan Warrington jon at shirwin.com
Tue Nov 25 00:01:20 CET 2003

Ah, ok I think I see where the communication problem was now.

What I was wanting to do, was have it so that my other components would 
only know of that scripting engine interface, and use that to register 
themselves at runtime when they are created, and therefore if my XYZ 
class changes all I have to do is recompile that.  Not have to generate 
new Boost.Python registration code, and recompile that wrapper.

App Starts
App creates an instance of Scripting Engine
App creates an instance of class XYZ
App passes scripting engine to XYZ->Init()
XYZ registers what it wants to be scriptable as scriptable

So, if I want to use javascript instead, I tell App to create a 
javascript engine instead, and then nothing else would need to change 
except the scripts being called.  No need to create new wrapper code.

Does that make more sense as to what I'm wanting to be able to do?  I'm 
assuming that it'd require certain restrictions on what can be 
registered, like the way I was doing the functions, where you can only 
register a specific function prototype, as long as it's not too 
restrictive, that's fine.


Ralf W. Grosse-Kunstleve wrote:

> --- Jonathan Warrington <jon at shirwin.com> wrote:
>>Yes I've looked at the tutorial, and all the examples use the macro 
>>BOOST_PYTHON_MODULE() which means the classes that will be scriptable 
>>will have to import the Boost.Python headers, and be compiled against 
> Why would that be? You only have to compile the wrapper code using the
> Boost.Python headers (and with that the Python headers).
> your_wrapper.cpp:
> #include <boost/python.hpp> // first to meet a Python requirement
> #include <your_library_headers_that_know_nothing_about_python.hpp>
> {
>   boost::python::class_<your_class_bar>("your_class_bar");
> }
> Compile and link against your_library.a or your_library.so. Look at the bjam
> toolsets to see how exactly it is done on each of the of platforms that
> Boost.Python was tested under (many).
> Ralf

More information about the Cplusplus-sig mailing list