Re: [pygccxml-development] special functions/operators
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2006-08-29 17:57:55
|
On 8/29/06, Matthias Baas <ba...@ir...> wrote: > Neal Becker wrote: > >>>> cls = mb.class_("X") > >>>> f = mb.free_function( "addAssign" ) > >>>> cls.add_method( f ) > > > > I don't understand all of what you guys said, but it sounds like this is what > > I had in mind. > > > > f = mb.free_function ("addAssign") > > > > what is "free_function"? Is this new or already existing? free_function returns a reference to free function declaration. It exists. > It's the syntax of the Py++ high-level API, the pypp_api equivalent is > the Function() method. > > So back to your initial example. Using the add_method approach you could > write the following: > > f = root.Function("addAssign") > f.rename("__iadd__") > f.setPolicy(return_self()) > root.Class("X").addMethod(f) > > Currently, you would have to write the following instead: > > root.Class("X").cdef("__iadd__", "addAssign", return_self()) > > > Well, if *I* had to choose in this example, I would still use the latter > option because of its brevity. Your goal has been to be less "low level" > and get to a "better" API. But frankly, I don't see how the first option > should have achieved these goals. In this specific case you are right. > But don't get me wrong, I don't say that add_method() is always a bad > thing and cdef() is always better. There's merit in having something > like add_method(), but probably not in this particular case (which was > used as an example that a new API should improve). Matthias, I think I still need this function, because it will improve few my scripts and I like the idea. Do you want to implement it? It could be a nice introduction to code creators factory. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |