Thread: [pygccxml-development] Trying to ramp up again
Brought to you by:
mbaas,
roman_yakovenko
From: Allen B. <al...@vr...> - 2006-05-11 15:51:48
|
Hello all. I am back at it and trying to wrap some libraries that used to use Pyste. Anyway, I have been out of the loop for a while and I wondered if someone could point me in the direction of what to look at to get back into things. I see there is a tutorial on the website for a module_builder interface. I assume that this is the high-level interface. Am I correct? The tutorial shows how to do some basic things but it does explain things like are the classes searched for recursively, mutli-matching, and all that stuff we were talking about the last time I was here. What is the best way to get up to speed on this stuff? Should I be reading API documentation? How do I generate it? Sorry for all the questions, I just want to get back up to speed as quickly as I can and I am sure you guys can point me in the right direction. :) Thanks, Allen |
From: Roman Y. <rom...@gm...> - 2006-05-11 18:26:28
|
On 5/11/06, Allen Bierbaum <al...@vr...> wrote: > Hello all. I am back at it and trying to wrap some libraries that used > to use Pyste. It is nice to read from you again :-). > Anyway, I have been out of the loop for a while and I wondered if > someone could point me in the direction of what to look at to get back > into things. I will try to do it. I re-wrote date_time tester. So may be it is a good id= ea to look at it, after tutorial example. > I see there is a tutorial on the website for a module_builder > interface. I assume that this is the high-level interface. Am I correct= ? Yes, you are. > The tutorial shows how to do some basic things but it does not explain > things like are the classes searched for recursively, mutli-matching, > and all that stuff we were talking about the last time I was here. I did not want to insert that staffs into tutorials. > What is the best way to get up to speed on this stuff? Just start working, I think that API is simple and intuitive. If you don't = mind I prefer you to use version from SVN. It is much better, then last release. > Should I be reading API documentation? Yes. In order to understand how selection API works, please read pygccxml/declarations/scopedef.py module. The short version is next: The are 2 sets of API: one set returns single object and raises exception if object not found. Another API set selects multiple objects. Lets learn member_function and member_functions api: def member_function ( self, name=3DNone, function=3DNone, return_type=3DNone, arg_types=3DNone, header_dir=3DNone, header_file=3DNone= , recursive=3DNone ): def member_functions( self, name=3DNone, function=3DNone, return_type=3DNone, arg_types=3DNone, header_dir=3DNone, header_file=3DNone= , recursive=3DNone, allow_empty=3DNone ): As you can see, they are almost identical. The only difference is "allow_em= pty" argument in "multi select" function. Now how does it works? Because those methods are defined on scopedef_t class, both class_t and namespace_t classes have them. It allows you to write next code mb =3D module_builder_t(...) my_class =3D mb.class_( "xxxx" ) my_class.member_functions( "do_smth", recursive=3DFalse ).exclude() If you just pass one argument to the "select" functions scopedef_t class wi= ll correctly find out what it is: name or custom function. my_class.member_functions( lambda decl: decl.name.endswith( '_impl' ) ) In all other cases you have to use keywords arguments. Now about defaults for recursive and allow_empty. As you can see in both functions this is None. The algorithm is simple: if allow_empty is None: use scopedef_t.ALLOW_EMPTY_MDECL_WRAPPER else: use it as is. The same is true for recursive argument. So, you are able to redefine behaviour for the whole project in one place. Now multi select functions return instance of "mdecl_wrapper_t" class. It a= llows you to "set" some attribute or call some function on all object in one line= : my_class.member_functions( "do_smth", recursive=3DFalse ).exclude() All member functions that match the criteria will be excluded. There is no = need to travel on them using loop. >How do I generate it? If you use SVN version, then it is very simple. Install epydoc. You have to install latest version of epydoc ( 3.0 alpha 2 ). python setup.py sdist or if you want to generate documentation only python setup.py doc > Sorry for all the questions, I just want to get back up to speed as > quickly as I can and I am sure you guys can point me in the right > direction. :) I hope, that was the right direction. Any way if you need more help we can talk on some IRC channel. > Thanks, > Allen --=20 Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Roman Y. <rom...@gm...> - 2006-05-11 19:21:05
|
On 5/11/06, Allen Bierbaum <al...@vr...> wrote: > All of my libraries use boost::shared_ptr's. > > How do I: > > - register held types for a class. The experimental pypp_api I did had > a .setHeldType() method, is there something similar still. In most cases pyplusplus will find out this automatically. Any way, pyplusplus/decl_wrappers class_t has held_type property. > - How do I generate "register_ptr_to_python" calls? Same as above. If it does not work for you you will need to modify code creators tree directly. So, if it will not work for you, I will show you the code. > - How do I generate "implicitly_convertible" calls? Same as above > - How do I add custom text (or the code creator for custom text) to a > decl wrapper? (I could probably find this in the code, but thought I > would ask first) You can use 2 methods defined on decl_wrapper.class_t class: add_code( code, works_on_instance=3DTrue ) add_wrapper_code( code ). > Thanks, > Allen P.S. Pay attention I redirect my answer to mailing list too. I want this information available to other people too. --=20 Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Allen B. <al...@vr...> - 2006-05-11 19:35:09
|
Roman Yakovenko wrote: > On 5/11/06, Allen Bierbaum <al...@vr...> wrote: > >> All of my libraries use boost::shared_ptr's. >> >> How do I: >> >> - register held types for a class. The experimental pypp_api I did had >> a .setHeldType() method, is there something similar still. > > > In most cases pyplusplus will find out this automatically. Any way, > pyplusplus/decl_wrappers class_t has held_type property. > >> - How do I generate "register_ptr_to_python" calls? > > > Same as above. If it does not work for you you will need to modify > code creators tree directly. So, if it will not work for you, I will > show you the code. Ok. I know that in my case this will not be automatically determined, so how would I do this. I was hoping that I would never have to search through the code creator tree. Would it be possible for me to just add custom text to the decl wrapper class? I think there was some functionality like this in an early version of the API that effectively allowed users to add any custom calls they needed inside the class scope of the generated code. -Allen > >> - How do I generate "implicitly_convertible" calls? > > > Same as above > >> - How do I add custom text (or the code creator for custom text) to a >> decl wrapper? (I could probably find this in the code, but thought I >> would ask first) > > > You can use 2 methods defined on decl_wrapper.class_t class: > > add_code( code, works_on_instance=True ) > add_wrapper_code( code ). > >> Thanks, >> Allen > > > P.S. Pay attention I redirect my answer to mailing list too. I want > this information > available to other people too. > |
From: Roman Y. <rom...@gm...> - 2006-05-11 19:41:05
|
On 5/11/06, Allen Bierbaum <al...@vr...> wrote: > Roman Yakovenko wrote: > > > On 5/11/06, Allen Bierbaum <al...@vr...> wrote: > > > >> All of my libraries use boost::shared_ptr's. > >> > >> How do I: > >> > >> - register held types for a class. The experimental pypp_api I did ha= d > >> a .setHeldType() method, is there something similar still. > > > > > > In most cases pyplusplus will find out this automatically. Any way, > > pyplusplus/decl_wrappers class_t has held_type property. > > > >> - How do I generate "register_ptr_to_python" calls? > > > > > > Same as above. If it does not work for you you will need to modify > > code creators tree directly. So, if it will not work for you, I will > > show you the code. > > Ok. I know that in my case this will not be automatically determined, > so how would I do this. When you will have more time, I would like to make sure that pyplusplus tre= ats your case. > I was hoping that I would never have to search through the code creator t= ree. There are use case where you will have to. > Would it be possible for me to just add custom text to the decl wrapper > class? I think there was some functionality like this in an early > version of the API that effectively allowed users to add any custom > calls they needed inside the class scope of the generated code. Yes, just use an API I gave you: add_code( your code, works_on_instance=3DFalse ) It should do the trick > -Allen --=20 Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Allen B. <al...@vr...> - 2006-05-12 16:14:06
|
Roman Yakovenko wrote: > On 5/11/06, Allen Bierbaum <al...@vr...> wrote: > >> All of my libraries use boost::shared_ptr's. >> >> How do I: >> >> - register held types for a class. The experimental pypp_api I did had >> a .setHeldType() method, is there something similar still. > > > In most cases pyplusplus will find out this automatically. Any way, > pyplusplus/decl_wrappers class_t has held_type property. What does pyplusplus use to determine this? I ask because it didn't work for any of my classes. I am not surprised it didn't work, but it may be interesting to understand why it is not working. -Allen > >> - How do I generate "register_ptr_to_python" calls? > > > Same as above. If it does not work for you you will need to modify > code creators tree directly. So, if it will not work for you, I will > show you the code. > >> - How do I generate "implicitly_convertible" calls? > > > Same as above > >> - How do I add custom text (or the code creator for custom text) to a >> decl wrapper? (I could probably find this in the code, but thought I >> would ask first) > > > You can use 2 methods defined on decl_wrapper.class_t class: > > add_code( code, works_on_instance=True ) > add_wrapper_code( code ). > >> Thanks, >> Allen > > > P.S. Pay attention I redirect my answer to mailing list too. I want > this information > available to other people too. > |
From: Roman Y. <rom...@gm...> - 2006-05-12 18:40:55
|
On 5/12/06, Allen Bierbaum <al...@vr...> wrote: > Roman Yakovenko wrote: > > In most cases pyplusplus will find out this automatically. Any way, > > pyplusplus/decl_wrappers class_t has held_type property. > > What does pyplusplus use to determine this? I ask because it didn't > work for any of my classes. When py++ creates code creators for your declarations, it registers every u= sed type ( =3D=3D return type and function arguments ) in "types database". After, all functions have been exported, py++ then queries that data base f= or help_type and register_ptr_to_python. Please take a look on module_creator.types_database.py file. By default py++ creates an instance of this class and passes it to module_creator.creator_t instance. module_builder.module_builder_t.build_code_creator function takes an argume= nt types_db, by default is None. You can create your own types_dn and pass it to py++. Or may be you can take a look on types_database_t class and fix it= ? > I am not surprised it didn't work, but it may be interesting to > understand why it is not working. I agree with you > -Allen --=20 Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Roman Y. <rom...@gm...> - 2006-05-12 18:20:02
|
On 5/12/06, Allen Bierbaum <al...@vr...> wrote: > Roman Yakovenko wrote: > > In most cases pyplusplus will find out this automatically. Any way, > > pyplusplus/decl_wrappers class_t has held_type property. > > Manually setting this lead to code that would not compile. The error is > below. May be you should set always_expose_using_scope flag to True. > It appears that once it had problems with the wapper class pointer type > after I set the held type. Is there something else I need to do to make > this work? Sorry, but I don't understand you, can you send me simple C++ code you want to export and your py++ script? Thanks > -Allen --=20 Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Roman Y. <rom...@gm...> - 2006-05-12 18:28:22
|
On 5/12/06, Allen Bierbaum <al...@vr...> wrote: > > > > > Yes, just use an API I gave you: > > > > add_code( your code, works_on_instance=3DFalse ) > > > > It should do the trick > > > I can't seem to find a similar API for adding code outside of a class. Because it does not exists. > For example if I want to add a custom .def at the global scope or put a > new method inline in the file or something like that. I think the > prototype API I had allowed custom code to be added to any decl (not > just classes). If you want to open this topic, please start another thread, with an exampl= e, that shows, how this functionality would help you. > -Allen > --=20 Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |