[C++-sig] Re: accessing instances of C++ objects in Python

Adrian Bentley adruab at hotmail.com
Sun Jan 11 01:33:14 CET 2004


Yeah, sorry, after I posted I realized a lot of what I said was really
unclear.

> Assuming this was really meant to be a question, and by "it" you mean
> the python function:  what does it mean for a class to be "exposed to"
> a python function?

What I essentially want is to send python an instance of a C++ object
(parameter to calling a Python function for instance) and for python to be
able to modify it.

I'm sort of new to using Python as a scripting language, so I'm not sure how
the interaction is supposed to occur.  I understand how you expose classes
for python to instantiate itself, but I haven't figured out how to have
things interact (i.e. create a structure in C++, pass it into a python
function and when I get back into C++ land, it will have been modified or
what not).

> Not in Python, directly.  Need a more detailed example of what you
> want to do.  Showing some Python and C++ code would help.

Ok, so here's what I want to do.  I'm making a componentized system for C++,
so at run time I want to group a bunch of components together and then
allocate all the data they've asked to see (point pos, matrix rot) in a big
block.  Then some how allow python to interact with this data object.  It
would be nice if I could just create properties that treat the space that
was allocated for pos and rot as variables in python.

The whole idea is to provide a scripting system to attach to this dynamic
object system and what not.

There are some reasons why I'm not just using Python to instantiate all the
objects:
1) the engine I'm writing is supposed to be dynamic, so it'd be nice to
allow Python to just hook in, just like any other language (which is one
reason why boost/python seemed cool :)

2) the interface for the C++ components to share their data is drastically
simplified if I can manually construct the composite objects (and their data
blocks as I mentioned before).

I certainly hope that I can figure this stuff out.  It looks like it could
be very promising if I could :).

Thanks for the response, it's nice to have people to help out when you've
got bizarre questions :).

> Don't read the source.  Check out the class_<...>::add_property member
> in the reference docs.

Will do... (more so than before at least :P).

Thanks again,
Adruab > Adrian Bentley




More information about the Cplusplus-sig mailing list