|
Re: Re: instantiating python objects within C++: msg#00294python.c++
David Abrahams wrote: The Boost.Python shared library has a converter registry where all of ok, this seems really to be the key. How does this work ? I'm a bit confused, as conceptually the lines BOOST_PYTHON_MODULE(Sandbox) { python::class_<Base> base_type("Base"); //... } create a type 'Sandbox.Base', i.e. the equivalent in C++ would be something like 'Sandbox::Base'. However, 'Sandbox' isn't a type, so I wonder how I can access the above type object from inside C++. Your example at the bottom of http://www.boost.org/libs/python/doc/tutorial/doc/derived_object_types.html hints a bit at how to instantiate such type objects, but I fail to see how I could do that from within a different 'scope'. What I'm really pondering about now is how to compare types, i.e. if I'v obtained a type from a python script, and I want to test whether this type derives from 'Sandbox.Base': from Sandbox import * class Derived(Base): def foobar(self): pass I should be able to take the python::object that is the (wrapper around the) python type, and compare it with the 'base_type' from the above snippet, i.e. doing something like python::handle<> result(PyRun_File(fp, const_cast<char *>(file.c_str()), Py_file_input, globals.ptr(), globals.ptr())); python::object derived_type = globals["Derived"]; I want to compare 'derived_type' with 'base_type', for example using Py_IsSubclass(derived_type.ptr(), base_type.ptr()) But how can I access 'base_type' ? It's a local variable in the scope of 'BOOST_PYTHON_MODULE(Sandbox), or is it ? Kind regards, Stefan |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: [newbie] Question on embedding/extending with boost::python: 00294, Dirk Gerrits |
|---|---|
| Next by Date: | Re: Re: instantiating python objects within C++: 00294, Ralf W. Grosse-Kunstleve |
| Previous by Thread: | Re: instantiating python objects within C++i: 00294, David Abrahams |
| Next by Thread: | Re: Re: instantiating python objects within C++: 00294, Ralf W. Grosse-Kunstleve |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |