Re: [C++-sig] pybindgen add_function_as_constructor

2009-04-27 Thread Gustavo Carneiro
2009/4/27 Robin Gilks 

> Robin Gilks wrote:
>
>> I've found the pybindgen commit for revision 628 and that fixes the
>> PyObject problem - got a new one now!! I can't work out the syntax to return
>> any sort of pointer for example
>>   mod.add_method('methodA', ReturnValue.new('uint8_t *'), [])
>> This is probably me again not understanding the Python side of things -
>> how would I return a string otherwise?
>>
>>
>> I see that some of the fixes are in the NS-3 project as
>> pybindgen-0.10.0.630 (I assume this means up to and including commit 630)
>> but there is no waf included in this project so I can't build it :-(
>>
>>
> Sorry about constantly replying to myself but the further I get into the
> pybindgen code, the more I get lost!! I've temporarily solved my 'uint8_t *'
> problem by using 'char *' but since I'll be using strings that may have
> embedded nulls I'm moving everything across to std::string types so that
> problem goes away:-)


Sounds good.

Sorry I wasn't online to help with the other questions.  I assume those
problems are solved, if not please ask again the questions.


> Where I've got to now is I can't find how to declare a docstring for a
> function or method.


Doesn't this work?

 module.add_function(..., docstring="this is a docstring")

OK, looking at the code I found two bugs in pybindgen wrt docstrings:

 1. there is a bug with handling docstrings with overloaded functions;
they will only work if the function is not overloaded with another function
with the same name;

 2. I forgot to add a docstring parameter to method objects.  But it's a
simple workaround, just:

method = MyClass.add_method(...)
method.docstring = "this is a docstring"

Again, only works if the method is not overloaded.

Regards,

-- 
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] pybindgen add_function_as_constructor

2009-04-27 Thread Robin Gilks

Gustavo Carneiro wrote:


Sounds good.

Sorry I wasn't online to help with the other questions.  I assume 
those problems are solved, if not please ask again the questions.



Where I've got to now is I can't find how to declare a docstring
for a function or method.


Doesn't this work?

 module.add_function(..., docstring="this is a docstring")

OK, looking at the code I found two bugs in pybindgen wrt docstrings:

 1. there is a bug with handling docstrings with overloaded 
functions; they will only work if the function is not overloaded with 
another function with the same name;


 2. I forgot to add a docstring parameter to method objects.  But 
it's a simple workaround, just:


method = MyClass.add_method(...)
method.docstring = "this is a docstring"

Again, only works if the method is not overloaded.
 


Thanks Gustavo

That gave me all the clues I needed. I've only just started using Python 
so my patch (below) is very much derived from the 'suck it and see' 
philosophy. It seems to work for me however!!


diff -PurN pybindgen/cppmethod.py 
../../pybindgen-0.10.0/pybindgen/cppmethod.py

--- pybindgen/cppmethod.py  2008-11-08 07:55:41.0 +1300
+++ ../../pybindgen-0.10.0/pybindgen/cppmethod.py   2009-04-27 
23:05:27.0 +1200

@@ -19,7 +19,7 @@
Class that generates a wrapper to a C++ class method
"""

-def __init__(self, method_name, return_value, parameters, 
is_static=False,
+def __init__(self, method_name, return_value, parameters, 
is_static=False, docstring=None,

 template_parameters=(), is_virtual=False, is_const=False,
 unblock_threads=None, is_pure_virtual=False,
 custom_template_method_name=None, visibility='public',
@@ -95,7 +95,7 @@
#self.static_decl = True
self._class = None
self._helper_class = None
-self.docstring = None
+self.docstring = docstring
self.wrapper_base_name = None
self.wrapper_actual_name = None
self.return_value = None


Cheers

--
Robin


===
This email, including any attachments, is only for the intended
addressee.  It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
altered or corrupted during transmission.
===

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig