Explorar o código

Lua : more switch statement fixes.

It's common in Haxe switch statements to list more than one possible
match for a case:

```haxe
var x = "foo";

switch(x){
    case "foo", "bar", "baz" : doSomething(x);
    default : null;
}
```

These need to get changed into "or" statements for the "if" statements
that lua uses to implement switch.  This change will enable that.
Justin Donaldson %!s(int64=10) %!d(string=hai) anos
pai
achega
2468b6437b
Modificáronse 1 ficheiros con 4 adicións e 3 borrados
  1. 4 3
      genlua.ml

+ 4 - 3
genlua.ml

@@ -671,13 +671,14 @@ and gen_expr ctx e =
 		spr ctx "}";
 	| TSwitch (e,cases,def) ->
 		List.iteri (fun cnt (el,e2) ->
-		    List.iter (fun e3 ->
-			if cnt == 0 then spr ctx "if " else spr ctx "elseif ";
+		    if cnt == 0 then spr ctx "if " else spr ctx "elseif ";
+		    List.iteri (fun ccnt e3 ->
+			if ccnt > 0 then spr ctx " or ";
 			gen_value ctx e;
 			spr ctx " == ";
 			gen_value ctx e3;
-			spr ctx " then "
 		    ) el;
+		    spr ctx " then ";
 		    let bend = open_block ctx in
 		    gen_block_element ctx e2;
 		    bend();