Browse Source

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 10 years ago
parent
commit
e7cbda1a42
1 changed files with 2 additions and 1 deletions
  1. 2 1
      genlua.ml

+ 2 - 1
genlua.ml

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