Browse Source

[lua] fixed entry-point handling (closes #9402)

Aleksandr Kuzmenko 5 years ago
parent
commit
31449b13d8

+ 17 - 8
src/generators/genlua.ml

@@ -2083,14 +2083,23 @@ let generate com =
 
     match com.main with
      | None -> ()
-     | Some e -> (match e.eexpr with
-         | TCall(e2,el) -> begin
-                spr ctx "_G.xpcall(";
-                gen_value ctx e2;
-                spr ctx ", _hx_error)";
-                newline ctx;
-            end
-         | _-> ());
+     | Some e ->
+        spr ctx "_G.xpcall(";
+        (match e.eexpr with
+         | TCall(e2,[]) ->
+            gen_value ctx e2;
+         | _->
+            let fn =
+                {
+                    tf_args = [];
+                    tf_type = com.basic.tvoid;
+                    tf_expr = mk (TBlock [e]) com.basic.tvoid e.epos;
+                }
+            in
+            gen_value ctx { e with eexpr = TFunction fn; etype = TFun ([],com.basic.tvoid) }
+        );
+        spr ctx ", _hx_error)";
+        newline ctx;
 
     if anyExposed then
         println ctx "return _hx_exports";

+ 1 - 0
tests/misc/lua/projects/.gitignore

@@ -0,0 +1 @@
+bin/*

+ 8 - 0
tests/misc/lua/projects/Issue9402/Main.hx

@@ -0,0 +1,8 @@
+import haxe.Timer;
+
+class Main {
+	static function main() {
+		Sys.stderr().writeString('Success');
+		Sys.stderr().flush();
+	}
+}

+ 3 - 0
tests/misc/lua/projects/Issue9402/compile.hxml

@@ -0,0 +1,3 @@
+-main Main
+-lua bin/test.lua
+--cmd lua bin/test.lua

+ 1 - 0
tests/misc/lua/projects/Issue9402/compile.hxml.stderr

@@ -0,0 +1 @@
+Success

+ 2 - 0
tests/misc/lua/run.hxml

@@ -0,0 +1,2 @@
+-cp ../src
+--run Main

+ 6 - 0
tests/runci/targets/Lua.hx

@@ -7,6 +7,9 @@ import haxe.io.*;
 using StringTools;
 
 class Lua {
+	static var miscLuaDir(get,never):String;
+	static inline function get_miscLuaDir() return miscDir + 'lua/';
+
 	static public function getLuaDependencies(){
 		switch (systemName){
 			case "Linux":
@@ -39,6 +42,9 @@ class Lua {
 
 		getLuaDependencies();
 
+		changeDirectory(miscLuaDir);
+		runCommand("haxe", ["run.hxml"]);
+
 		for (lv in ["-l5.1", "-l5.2", "-l5.3", "-j2.0", "-j2.1" ]){
 
 			var envpath = Sys.getEnv("HOME") + '/lua_env$lv';