浏览代码

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 10 年之前
父节点
当前提交
2468b6437b
共有 1 个文件被更改,包括 4 次插入3 次删除
  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();