瀏覽代碼

fixed neko native enum serialization.

Nicolas Cannasse 19 年之前
父節點
當前提交
0a60ce56a3
共有 2 個文件被更改,包括 18 次插入4 次删除
  1. 3 2
      genneko.ml
  2. 15 2
      std/neko/Boot.hx

+ 3 - 2
genneko.ml

@@ -505,8 +505,8 @@ let gen_enum_constr ctx path c =
 			),p)
 		| _ ->
 			(EBlock [
-				(EVars ["@tmp",Some (EObject ["tag" , str p c.ef_name],p)],p);
-				call p (builtin p "objsetproto") [ident p "@tmp"; field p path "prototype"];
+				(EVars ["@tmp",Some (EObject ["tag" , str p c.ef_name; "__serialize" , ident p "@tag_serialize"],p)],p);
+				call p (builtin p "objsetproto") [ident p "@tmp"; field p path "prototype"];				
 				ident p "@tmp";
 			],p)
 	),p)
@@ -655,6 +655,7 @@ let generate file types hres libs =
 		"@classes = $new(null);" ^
 		"@enum_to_string = function() { return neko.Boot.__enum_str(this); };" ^
 		"@serialize = function() { return neko.Boot.__serialize(this); };" ^ 
+		"@tag_serialize = function() { return neko.Boot.__tagserialize(this); };" ^ 
 		generate_libs_init libs
 	) , { psource = "<header>"; pline = 1; } in
 	let packs = List.concat (List.map (gen_package ctx h) types) in

+ 15 - 2
std/neko/Boot.hx

@@ -105,6 +105,15 @@ class Boot {
 			throw "Can't serialize";
 		}
 	}
+	
+	private static function __tagserialize(o) untyped {
+		var n = o.__enum__.__ename__;
+		var x = __dollar__amake(n.length + 1);
+		for( i in 0...n.length )
+			x[i] = n[i].__s;
+		x[n.length] = o.tag;
+		return x;
+	}
 
 	private static function __unserialize(v) {
 		untyped {
@@ -119,8 +128,12 @@ class Boot {
 				if( cl == null )
 					throw ("Class not found " + Std.string(v));
 			}
-			if( cl.__name__ != null || cl.__ename__ != null )
-				return cl.prototype;
+			if( __dollar__typeof(cl) == __dollar__tobject ) {
+				if( cl.__name__ != null || cl.__ename__ != null )
+					return cl.prototype;
+				if( cl.__enum__ != null && __dollar__typeof(cl.tag) == __dollar__tstring )
+					return cl;
+			}
 			throw "Invalid class " + Std.string(v);
 		}
 	}