On Fri, Feb 4, 2011 at 12:28 AM, Dan Eicher <[email protected]> wrote: > On Thu, Feb 3, 2011 at 2:54 PM, Campbell Barton <[email protected]> wrote: > >> -- snip -- >> >> To see what I mean about sloppy argument parsing, see comparison of >> 2.4x and 2.5x code below - both the same function though 2.5x uses >> mathutils_array_parse() utility function. >> The 2.4x code even had a memory leak for some time (refcount error). >> >> # --- 2.5x Code >> -- snip -- > It's actually pretty easy to do this type of overloading, you just > need python to do the heavy lifting through > PyArg_ParseTuple[AndKeywords]. Pybindgen uses this method in its > generated code and it works very well. > > The gist -- multiple functions that the main method calls and once it > finds one that doesn't throw an exception (from function args not > matching) then that's the one it uses. The code is nicely separated so > you don't end up with a bunch of if else blocks and everyone is happy. > > I would be simpler to just show some code than describe it methinks > > Dan
As Alex suggests, keywords only args could be used in this case: Euler(x, y, x, order='XZY') I don't see this as especially better or worse, just different, but I'm also not interested to change. I've seen PyArg_ParseTuple[AndKeywords] used as you suggest but I rather not depend on python exceptions for argument parsing with constructors, this would give noticeable slowdown if defining mathutils types in a loop. _______________________________________________ Bf-committers mailing list [email protected] http://lists.blender.org/mailman/listinfo/bf-committers
