Ver Fonte

Lua : Fix do-while syntax

Lua doesn't have do-while syntax.  I was originally just copying the
expression from the "while" statement once more, and using it as the do
expression.  However, it's possible to "break" from this do section as
well.  It seems the best way to replicate this in lua is to emulate the
"do" block with a separate "while" statement that will automitically
break when it reaches the end... unless the generated code issues a
"break" first.
Justin Donaldson há 10 anos atrás
pai
commit
e7cbda1a42
1 ficheiros alterados com 2 adições e 1 exclusões
  1. 2 1
      genlua.ml

+ 2 - 1
genlua.ml

@@ -604,8 +604,9 @@ and gen_expr ctx e =
 		spr ctx "end ";
 	| TWhile (cond,e,Ast.DoWhile) ->
 		let handle_break = handle_break ctx e in
+		spr ctx "while true do ";
 		gen_expr ctx e;
-		spr ctx "while ";
+		spr ctx "break end while ";
 		gen_cond ctx cond;
 		spr ctx " do ";
 		gen_expr ctx e;