Browse Source

Lua iife and semicolons

I was using iifes to wrap certain statements into expressions.
Unfortunately, this causes problems when the immediately preceding
statement is itself a function call.  Here's what generated code looks
like:

```haxe
var x = 0;
Foo.bar(0);
x+=1;
```

```lua
local x = 0
Foo.bar(0)
(function() x = x + 1 return x);
```

The problem is that actual lua expression ends up being interpreted as:

```lua
Foo.bar(0)(function() x = x + 1 return x);
```

So, it's necessary to insert some semicolons between expressions.  The
best place to do it is after relevant gen_block_element calls.  I've
also tweaked some newline calls to tidy things up a bit.
Justin Donaldson 10 năm trước cách đây
mục cha
commit
ca8ae55c79
1 tập tin đã thay đổi với 4 bổ sung5 xóa
  1. 4 5
      genlua.ml

+ 4 - 5
genlua.ml

@@ -498,8 +498,7 @@ and gen_expr ctx e =
 		gen_expr ctx e2;
 		bend();
 		newline ctx;
-		spr ctx "end";
-		newline ctx);
+		spr ctx "end");
 	| TUnop ((Increment|Decrement) as op,unop_flag, e) ->
 		spr ctx "(function() ";
 		gen_value ctx e;
@@ -568,8 +567,8 @@ and gen_expr ctx e =
 		bend();
 		newline ctx;
 		spr ctx "end";
-		newline ctx;
 		handle_break();
+		newline ctx;
 	| TTry (e,catchs) ->
 		spr ctx "try ";
 		gen_expr ctx e;
@@ -683,8 +682,8 @@ and gen_block_element ?(after=false) ctx e =
 	| _ ->
 		if not after then newline ctx;
 		gen_expr ctx e;
-		spr ctx ";";
-		if after then newline ctx
+		semicolon ctx;
+		if after then newline ctx;
 
 and gen_value ctx e =
 	let assign e =