Re: [pygccxml-development] special functions/operators
Brought to you by:
mbaas,
roman_yakovenko
From: Matthias B. <ba...@ir...> - 2006-08-29 16:48:34
|
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? 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. 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 - |