From 62fb546f2746037762554d0c010ed4e4ce4bb80d Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Fri, 17 Apr 2009 21:23:23 +0000 Subject: [PATCH] Check this out. This little buddy rocks. I sorta want to make a new FunctionUtil so that I can use it with impunity everwhere without having to include the other crap in here. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5730 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/Util.as | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/as/com/threerings/util/Util.as b/src/as/com/threerings/util/Util.as index d449ba1ac..246544ec1 100644 --- a/src/as/com/threerings/util/Util.as +++ b/src/as/com/threerings/util/Util.as @@ -59,6 +59,19 @@ public class Util } } + /** + * Return a var-args function that will attempt to pass only the arguments accepted by the + * passed-in function. Does not work if the passed-in function is varargs, and anyway + * then you don't need adapting, do you? + */ + public static function adapt (fn :Function) :Function + { + return function (... args) :* { + args.length = fn.length; // fit the args to the fn, filling in 'undefined' if growing + return fn.apply(null, args); + } + } + /** * Returns true if the specified object is just a regular old associative hash. */