Browse Source

Lua : Update Reflect.callMethod

This method is still a wip, but it's a decent first attempt at providing
an "apply" mechanism in lua that works for the equivalent Haxe reflect
method.
Justin Donaldson 10 years ago
parent
commit
061b86d7cc
1 changed files with 6 additions and 1 deletions
  1. 6 1
      std/lua/_std/Reflect.hx

+ 6 - 1
std/lua/_std/Reflect.hx

@@ -44,7 +44,12 @@
 	}
 	}
 
 
 	public inline static function callMethod( o : Dynamic, func : haxe.Constraints.Function, args : Array<Dynamic> ) : Dynamic untyped {
 	public inline static function callMethod( o : Dynamic, func : haxe.Constraints.Function, args : Array<Dynamic> ) : Dynamic untyped {
-		return func.apply(o,args);
+		if (args == null || args.length == 0){
+			return func(o);
+		} else {
+			var new_args = [o].concat(args);
+			return func(unpack(new_args,1,lua.TableTools.maxn(untyped new_args)));
+		}
 	}
 	}
 
 
 	public static function fields( o : Dynamic ) : Array<String> {
 	public static function fields( o : Dynamic ) : Array<String> {