瀏覽代碼

Lua : Fix operator precedence issue

Lua will interpret this a comparison of an int to a boolean:

4 > 3 ~= true

It's necessary to wrap both expressions in parens
Justin Donaldson 10 年之前
父節點
當前提交
60b933c852
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      genlua.ml

+ 4 - 0
genlua.ml

@@ -1038,13 +1038,17 @@ and gen_tbinop ctx op e1 e2 =
 	    gen_value ctx e2;
 	    spr ctx ") ";
     | _ -> begin
+	    spr ctx "(";
 	    gen_value ctx e1;
+	    spr ctx ")";
 	    (match op with
 		| Ast.OpNotEq -> print ctx " ~= ";
 		| Ast.OpBoolAnd -> print ctx " and ";
 		| Ast.OpBoolOr -> print ctx " or ";
 		| _ -> print ctx " %s " (Ast.s_binop op));
+	    spr ctx "(";
 	    gen_value ctx e2;
+	    spr ctx ")";
 	    end;
     );