Re: [C++-sig] Callbacks in PyBindGen

2010-05-19 Thread Gustavo Carneiro
On Tue, May 18, 2010 at 14:23, cammm  wrote:

>
> So I've just started playing with pybindgen and having used pyobject plus
> and
> boost::python before I have to say, it is a breathe of fresh air.
>
> Simple, explicit, fast and written in python. I'm not a fan of automatic
> coverage / source code parsing, explicit description of the python
> interface
> doesn't take that long and validates what you are doing. It is also nice
> not
> having thousands of files and a large build process as you get with boost,
> when all you want is a nice way to do python bindings.
>
> Many thanks to you Gustavo for a brilliant project and I encourage everyone
> to try it out and get behind him to help develop it.
>

Thanks, glad you like it :-)


>
> One thing I would really like to see go in is callback methods. Was there
> anything technical blocking this or just a case of haven't gotten to it
> yet?
> You mention in the docs it is easy to working around with some extra code,
> do you have a simple example of that working?
>

I have not enough time and motivation.  And I'm not sure how much effort it
would take.

There is some callback support code in NS-3 (www.nsnam.org), but in NS-3
"callbacks" are actually objects.  It's not a very simple example to learn
from.

I will try to come up with a simple example soon.


>
> Again, kudos and thanks :-)
> -
> Cameron
> --
> View this message in context:
> http://old.nabble.com/Callbacks-in-PyBindGen-tp28595532p28595532.html
> Sent from the Python - c++-sig mailing list archive at Nabble.com.
>
> ___
> Cplusplus-sig mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>



-- 
Gustavo J. A. M. Carneiro
INESC Porto, UTM, WiN, http://win.inescporto.pt/gjc
"The universe is always one step beyond logic." -- Frank Herbert
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] Callbacks in PyBindGen

2010-05-19 Thread Gustavo Carneiro
Example: http://bazaar.launchpad.net/~gjc/pybindgen/trunk/revision/766

(don't forget
the previous revision 765 for a bug fix)

On Wed, May 19, 2010 at 10:36, Gustavo Carneiro wrote:

>
>
> On Tue, May 18, 2010 at 14:23, cammm  wrote:
>
>>
>> So I've just started playing with pybindgen and having used pyobject plus
>> and
>> boost::python before I have to say, it is a breathe of fresh air.
>>
>> Simple, explicit, fast and written in python. I'm not a fan of automatic
>> coverage / source code parsing, explicit description of the python
>> interface
>> doesn't take that long and validates what you are doing. It is also nice
>> not
>> having thousands of files and a large build process as you get with boost,
>> when all you want is a nice way to do python bindings.
>>
>> Many thanks to you Gustavo for a brilliant project and I encourage
>> everyone
>> to try it out and get behind him to help develop it.
>>
>
> Thanks, glad you like it :-)
>
>
>>
>> One thing I would really like to see go in is callback methods. Was there
>> anything technical blocking this or just a case of haven't gotten to it
>> yet?
>> You mention in the docs it is easy to working around with some extra code,
>> do you have a simple example of that working?
>>
>
> I have not enough time and motivation.  And I'm not sure how much effort it
> would take.
>
> There is some callback support code in NS-3 (www.nsnam.org), but in NS-3
> "callbacks" are actually objects.  It's not a very simple example to learn
> from.
>
> I will try to come up with a simple example soon.
>
>
>>
>> Again, kudos and thanks :-)
>> -
>> Cameron
>> --
>> View this message in context:
>> http://old.nabble.com/Callbacks-in-PyBindGen-tp28595532p28595532.html
>> Sent from the Python - c++-sig mailing list archive at Nabble.com.
>>
>> ___
>> Cplusplus-sig mailing list
>> [email protected]
>> http://mail.python.org/mailman/listinfo/cplusplus-sig
>>
>
>
>
> --
> Gustavo J. A. M. Carneiro
> INESC Porto, UTM, WiN, http://win.inescporto.pt/gjc
> "The universe is always one step beyond logic." -- Frank Herbert
>



-- 
Gustavo J. A. M. Carneiro
INESC Porto, UTM, WiN, http://win.inescporto.pt/gjc
"The universe is always one step beyond logic." -- Frank Herbert
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

[C++-sig] Problem with overloading between int and double

2010-05-19 Thread Thomas Daniel
I have a class with "create" methods for different types of arguments:
#include 

class Test {
public:
Test() {}
Test(int x) : _type(x) {}
static Test create(int) { return Test(0); }
static Test create(double)  { return Test(1); }
static Test create(const char*) { return Test(2); }
int get_type() const { return _type; }
private:
int _type;
};

using namespace boost::python;

BOOST_PYTHON_MODULE(Test) {
class_("Test")
.def("create", (Test (*)(int)) &Test::create)
.def("create", (Test (*)(double))  &Test::create)
.def("create", (Test (*)(const char*)) &Test::create)
.def("get_type",  &Test::get_type)
.staticmethod("create")
;
}

The python wrappers created by boost don't seem to distinguish between
create(int) and create(double), although they do notice create(const char*):
>>> from Test import *
>>> x = Test.create(0)
>>> print x.get_type()
1
>>> x = Test.create(0.0)
>>> print x.get_type()
1
>>> y = Test.create("hi")
>>> print y.get_type()
2


Any ideas what I do wrong?

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Problem with overloading between int and double

2010-05-19 Thread Jim Bosch

On 05/19/2010 06:23 PM, Thomas Daniel wrote:

The python wrappers created by boost don't seem to distinguish between
create(int) and create(double), although they do notice create(const char*):
   




Any ideas what I do wrong?

   


You aren't doing anything wrong.  The problem is that the boost.python 
overload matcher for double also matches integers (I think it probably 
should, generally), and that's getting tried first; only when the first 
overload fails does Boost.Python try another.


A workaround is to change the order to expose them (the last one exposed 
gets tried first):


BOOST_PYTHON_MODULE(Test) {
class_("Test")
.def("create", (Test (*)(double))&Test::create)
.def("create", (Test (*)(int))&Test::create)
.def("create", (Test (*)(const char*))&Test::create)
.def("get_type",&Test::get_type)
.staticmethod("create")
;
}


I admit it's not a very satisfying solution.  Maybe someone else has a 
better idea, but I think fixing this in Boost.Python would require a lot 
of work.


Jim Bosch
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Problem with overloading between int and double

2010-05-19 Thread Ralf W. Grosse-Kunstleve
> I admit it's not a very satisfying solution.  Maybe someone else has a better 
> idea,
> but I think fixing this in Boost.Python would require a lot of work.


Troy did the work already but it isn't in the trunk.
IIUC the additional price is increased extension sizes (but Troy's changes
seem to go far beyond an enhanced overload mechanism so it is difficult to
tell).

There is another way to achieve what you want: just do the overload
resolution yourself. Wrap a function that takes boost::python::object
as the argument, then use extract<> or the raw Python API to inspect
the object and call the best C++ overload.

Ralf
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig