Browse Source

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 years ago
parent
commit
60b933c852
1 changed files with 4 additions and 0 deletions
  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;
     );