Re: [C++-sig] Function handling with Boost

2009-06-24 Thread Christopher Schramm
Thomas Berg wrote: > bp::scope sc(main); > bp::def("function", myfunction, "function helpstring"); Now that looks interesting. I'll implement that and let you know if it leads to any further problems. But it sounds like the perfect solution. > Found this out by reading the source

Re: [C++-sig] Function handling with Boost

2009-06-24 Thread Christopher Schramm
> Thomas Berg wrote: >> bp::object function = bp::object(myfunction); > > Great! And it was that simple... But wait... Giving that a second thought I don't think that's going to exhaust bpy's full potential. At least I don't see a way to use it's docstring handling or call policies. I'll tes

Re: [C++-sig] Function handling with Boost

2009-06-24 Thread Christopher Schramm
Thomas Berg wrote: > bp::object function = bp::object(myfunction); Great! And it was that simple... Thanks! ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] Function handling with Boost

2009-06-23 Thread Christopher Schramm
Stefan Seefeld wrote: > An alternative is not to use BOOST_PYTHON_MODULE at all, but set up > converters in ordinary C++ code. In the following I set up a Python > interpreter in my main application, inject a (C++) base class, run a > Python script that adds a derived class, then instantiate and ru

Re: [C++-sig] Function handling with Boost

2009-06-23 Thread Christopher Schramm
Stefan Seefeld wrote: > You need a module into which to inject the symbols you export. That is > true no matter the (meta)type of what you export, i.e. classes, > functions, etc. > Once you have that module set up (via BOOST_PYTHON_MODULE), you can > instantiate the newly created Python objects (ty

Re: [C++-sig] Function handling with Boost

2009-06-23 Thread Christopher Schramm
Stefan Seefeld wrote: > I read your original mail, but I didn't understand what you are trying > to achieve. You certainly can export functions to python: > > void foo(...); > > ... > > bpl::def("foo", foo); > > > works just fine. There shouldn't be any need to wrap the function in a > class (

Re: [C++-sig] Function handling with Boost

2009-06-23 Thread Christopher Schramm
Mmmkay, looks like I found a dirty little workaround: I put the C++ functions, I want to expose into a dummy class: class Dummy { int f1(str arg1, ... void f2(tuple arg1, ... } And then create a bpy object from it: object tmp = class_("dummy") .def("f1", &Dummy::f1)

[C++-sig] Function handling with Boost

2009-06-21 Thread Christopher Schramm
arg2); if (arg2.get()) { ... } ... ...bpy::extract(bpy::object(arg1))... return Py_BuildValue("s", my_cstr_result); } Beside the problems already mentioned this means missing bpy features for the functions like automatic docstrings, return value policies etc.