[python] Setting a pointer into an object

Hi, I am trying to do the following: SomeClassOfMine* myInstance; // Assume valid pointer boost::python::object myObject( myInstance ); However, doing so causes an exception to be thrown when I run my application. The exception thrown is below (Note I'm using MSVC9): First-chance exception at 0x7c812aeb in Crusades_Debug.exe: Microsoft C++ exception: boost::python::error_already_set at memory location 0x0012f0cc.. Unhandled exception at 0x7c812aeb in Crusades_Debug.exe: Microsoft C++ exception: boost::python::error_already_set at memory location 0x0012f0cc.. How can I assign the pointer above to a boost::python::object? I'm trying to give my python scripts access to an instance of a class that I haven't really exposed to Python yet, so I'm not sure of the consequences of that. I was going to extend the SomeClassOfMine class to python later on after I verify that I can get this working. Once I have myObject in a valid state, I will insert it into the __main__'s __dict__ namespace for a specific module so that it has access to it as a global python variable. Help is appreciated.

on Tue Sep 30 2008, "Robert Dailey" <rcdailey-AT-gmail.com> wrote:
Hi,
I am trying to do the following:
SomeClassOfMine* myInstance; // Assume valid pointer boost::python::object myObject( myInstance );
However, doing so causes an exception to be thrown when I run my application. The exception thrown is below (Note I'm using MSVC9):
First-chance exception at 0x7c812aeb in Crusades_Debug.exe: Microsoft C++ exception: boost::python::error_already_set at memory location 0x0012f0cc.. Unhandled exception at 0x7c812aeb in Crusades_Debug.exe: Microsoft C++ exception: boost::python::error_already_set at memory location 0x0012f0cc..
How can I assign the pointer above to a boost::python::object? I'm trying to give my python scripts access to an instance of a class that I haven't really exposed to Python yet, so I'm not sure of the consequences of that. I was going to extend the SomeClassOfMine class to python later on after I verify that I can get this working. Once I have myObject in a valid state, I will insert it into the __main__'s __dict__ namespace for a specific module so that it has access to it as a global python variable. Help is appreciated.
Just wrap the class without exposing any of its interesting parts and you should be fine: class_<SomeClassOfMine>("SomeClassOfMine"); -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On Tue, Sep 30, 2008 at 3:14 PM, David Abrahams <dave@boostpro.com> wrote:
Just wrap the class without exposing any of its interesting parts and you should be fine:
class_<SomeClassOfMine>("SomeClassOfMine");
Thanks David. After I posted my original inquiry I found out through PyErr_Print() that it needed the class to be exposed to Python. However, I no longer wish to expose the class, but instead I want to define a global function in a python script that I'm loading. For example, I would add this function to the namespace that I pass into exec_file(). The C++ function I want to expose looks like: static Rocket::Core::Context* GetContext( std::string const& context_name ); All I'm doing is this: boost::python::object MyNewFunction( &GetContext ); However, when I compile this I get: error C2027: use of undefined type 'boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning<T>' with [ T=result_t ] I can't exactly use return policies here since I'm not using def(). How can I make this work?

On Tue, Sep 30, 2008 at 4:05 PM, Robert Dailey <rcdailey@gmail.com> wrote:
On Tue, Sep 30, 2008 at 3:14 PM, David Abrahams <dave@boostpro.com> wrote:
Just wrap the class without exposing any of its interesting parts and you should be fine:
class_<SomeClassOfMine>("SomeClassOfMine");
Thanks David.
After I posted my original inquiry I found out through PyErr_Print() that it needed the class to be exposed to Python. However, I no longer wish to expose the class, but instead I want to define a global function in a python script that I'm loading.
For example, I would add this function to the namespace that I pass into exec_file().
The C++ function I want to expose looks like:
static Rocket::Core::Context* GetContext( std::string const& context_name );
All I'm doing is this:
boost::python::object MyNewFunction( &GetContext );
However, when I compile this I get:
error C2027: use of undefined type 'boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning<T>' with [ T=result_t ]
I can't exactly use return policies here since I'm not using def(). How can I make this work?
After a lot more research, I found out about make_function(). This is what def() uses and seems to be exactly what I"m looking for.
participants (2)
-
David Abrahams
-
Robert Dailey