Explorar o código

added __setfield__ (haxe/PHP)
added _hx_set_method (haXe/PHP)
reverted Reflect.setField
removed comments in BytesInput

Franco Ponticelli %!s(int64=16) %!d(string=hai) anos
pai
achega
e5f1b4da07
Modificáronse 4 ficheiros con 25 adicións e 31 borrados
  1. 17 24
      genphp.ml
  2. 2 3
      std/Reflect.hx
  3. 1 4
      std/haxe/io/BytesInput.hx
  4. 5 0
      std/php/Boot.hx

+ 17 - 24
genphp.ml

@@ -466,6 +466,18 @@ let rec gen_array_args ctx lst =
 		gen_array_args ctx t
 		
 and gen_call ctx e el =
+	let rec genargs lst =
+		(match lst with
+		| [] -> ()
+		| h :: [] ->
+			spr ctx " = ";
+			gen_value ctx h;
+		| h :: t ->
+			spr ctx "[";
+			gen_value ctx h;
+			spr ctx "]";
+			genargs t)
+	in
 	match e.eexpr , el with
 	| TConst TSuper , params ->
 		(match ctx.curclass.cl_super with
@@ -484,35 +496,16 @@ and gen_call ctx e el =
 			spr ctx ")";
 		);
 	| TLocal "__set__" , { eexpr = TConst (TString code) } :: el ->
-		let rec genargs lst =
-			(match lst with
-			| [] -> ()
-			| h :: [] ->
-				spr ctx " = ";
-				gen_value ctx h;
-			| h :: t ->
-				spr ctx "[";
-				gen_value ctx h;
-				spr ctx "]";
-				genargs t)
-		in
 		print ctx "%s$%s" (escphp ctx.quotes) code;
 		genargs el;
 	| TLocal "__set__" , e :: el ->
-		let rec genargs lst =
-			(match lst with
-			| [] -> ()
-			| h :: [] ->
-				spr ctx " = ";
-				gen_value ctx h;
-			| h :: t ->
-				spr ctx "[";
-				gen_value ctx h;
-				spr ctx "]";
-				genargs t)
-		in
 		gen_value ctx e;
 		genargs el;
+	| TLocal "__setfield__" , e :: (f :: el) ->
+		gen_value ctx e;
+		spr ctx "->";
+		gen_value ctx f;
+		genargs el;
 	| TLocal "__field__" , e :: (f :: el) ->
 		gen_value ctx e;
 		spr ctx "->";

+ 2 - 3
std/Reflect.hx

@@ -80,7 +80,7 @@ class Reflect {
 	/**
 		Set an object field value.
 	**/
-	public #if !php inline #end static function setField( o : Dynamic, field : String, value : Dynamic ) : Void untyped {
+	public inline static function setField( o : Dynamic, field : String, value : Dynamic ) : Void untyped {
 		#if flash
 			o[field] = value;
 		#elseif js
@@ -89,8 +89,7 @@ class Reflect {
 			if( __dollar__typeof(o) == __dollar__tobject )
 				__dollar__objset(o,__dollar__hash(field.__s),value);
 		#elseif php
-			untyped __php__("if (is_array($value) && get_class($value[0]) == '_hx_lambda') $value[0]->scope = $o");
-			untyped __php__("$o->$field = $value");
+			__setfield__(o, field, value);
 		#end
 	}
 

+ 1 - 4
std/haxe/io/BytesInput.hx

@@ -86,10 +86,7 @@ class BytesInput extends Input {
 			#if neko
 			try untyped __dollar__sblit(buf.getData(),pos,b,this.pos,len) catch( e : Dynamic ) throw Error.OutsideBounds;
 			#elseif php
-			// TODO: test me
-			untyped __php__("$buf->b = substr($buf->b, 0, $pos) . substr($this->b, $this->pos, $len) . substr($buf->b, $pos+$len)"); //__call__("substr", b, 0, pos)+__call__("substr", src.b, srcpos, len)+__call__("substr", b, pos+len);
-//			var b2 = untyped __php__("& $buf->b");
-//			b2 = untyped __call__("substr", b2, 0, pos)+__call__("substr", b, 0, len)+__call__("substr", b2, pos+len);
+			untyped __php__("$buf->b = substr($buf->b, 0, $pos) . substr($this->b, $this->pos, $len) . substr($buf->b, $pos+$len)");
 			#else
 			var b1 = b;
 			var b2 = buf.getData();

+ 5 - 0
std/php/Boot.hx

@@ -338,6 +338,11 @@ function _hx_register_type($t) {
 		php_Boot::$tpaths[$t->__tname__] = $t->__path__;
 }
 
+function _hx_set_method($o, $field, $func) {
+	$value[0]->scope = $o; 
+	$o->$field = $value;
+}
+
 function _hx_shift_right($v, $n) {
 	$z = 0x80000000;
 	if ($z & $v) {