Преглед изворни кода

[lua] keep string fields for reflection, iterate string methods properly. close #6276

Justin Donaldson пре 8 година
родитељ
комит
80b0d79374

+ 4 - 0
src/generators/genlua.ml

@@ -508,6 +508,10 @@ and gen_expr ?(local=true) ctx e = begin
 		print ctx "_iterator(";
 		gen_value ctx x;
 		print ctx ")";
+	| TField (e, f) when is_string_expr e ->
+                spr ctx "(";
+                gen_value ctx e;
+                print ctx ").%s" (field_name f);
 	| TField (x,FClosure (_,f)) ->
 		add_feature ctx "use._hx_bind";
 		(match x.eexpr with

+ 0 - 1
src/optimization/dce.ml

@@ -56,7 +56,6 @@ let keep_whole_class dce c =
 	|| super_forces_keep c
 	|| (match c with
 		| { cl_path = ([],("Math"|"Array"))} when dce.com.platform = Js -> false
-		| { cl_path = ([],("Math"|"Array"|"String"))} when dce.com.platform = Lua -> false
 		| { cl_extern = true }
 		| { cl_path = ["flash";"_Boot"],"RealBoot" } -> true
 		| { cl_path = [],"String" }

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

@@ -90,7 +90,11 @@ import lua.Boot;
 	}
 
 	public static function fields( o : Dynamic ) : Array<String> {
-		return [for (f in lua.Boot.fieldIterator(o)) f];
+		if (lua.Lua.type(o) == "string"){
+			return Reflect.fields(untyped String.prototype);
+		} else {
+			return [for (f in lua.Boot.fieldIterator(o)) f];
+		}
 	}
 
 	public static function isFunction( f : Dynamic ) : Bool {

+ 10 - 0
tests/unit/src/unit/issues/Issue6276.hx

@@ -0,0 +1,10 @@
+package unit.issues;
+
+class Issue6276 extends unit.Test {
+	function test(){
+		var s = "foo";
+		var indexOf = Reflect.field(s, "indexOf");
+		var pos = Reflect.callMethod(s, indexOf, ["o"]);
+		eq(pos, 1);
+	}
+}