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

Lua : Use 0-based indexing for enum values.

Haxe enums are typically array run-time values, and the expression is
generated further upstream in the ast generator.  I'm not sure if it's a
good idea to try and make that use 1-based indexing for raw lua tables,
or if we should just use 0-based indexing here.  For now, I'm using
0-based indexing, and adding a todo for later.
Justin Donaldson пре 10 година
родитељ
комит
52e01079e0
1 измењених фајлова са 4 додато и 2 уклоњено
  1. 4 2
      genlua.ml

+ 4 - 2
genlua.ml

@@ -1475,7 +1475,8 @@ let generate_enum ctx e =
 			spr ctx " return _x; end ";
 			ctx.separator <- true;
 		| _ ->
-			print ctx "{\"%s\",%d}" f.ef_name f.ef_index;
+			(* TODO: Figure out how to use 1-based indexing for enum values. *)
+			print ctx "{[0]=\"%s\",%d}" f.ef_name f.ef_index;
 			newline ctx;
 			if has_feature ctx "may_print_enum" then begin
 				print ctx "%s%s.toString = _estr" p (field f.ef_name);
@@ -1616,8 +1617,9 @@ let generate com =
 	spr ctx "pcall(require, 'bit32') pcall(require, 'bit') bit = bit or bit32"; newline ctx;
 	spr ctx "print = print or (function()end)"; newline ctx;
 
+	spr ctx "_hxClasses = {}"; semicolon ctx; newline ctx;
 	let vars = [] in
-	let vars = (if has_feature ctx "Type.resolveClass" || has_feature ctx "Type.resolveEnum" then ("_hxClasses = " ^ "{}") :: vars else vars) in
+	(* let vars = (if has_feature ctx "Type.resolveClass" || has_feature ctx "Type.resolveEnum" then ("_hxClasses = " ^ "{}") :: vars else vars) in *)
 	let vars = if has_feature ctx "may_print_enum"
 		then ("_estr = function()  return " ^ (ctx.type_accessor (TClassDecl { null_class with cl_path = ["lua"],"Boot" })) ^ ".__string_rec(self,''); end") :: vars
 		else vars in