|
@@ -47,6 +47,7 @@ type ctx = {
|
|
|
mutable separator : bool;
|
|
|
mutable found_expose : bool;
|
|
|
mutable lua_jit : bool;
|
|
|
+ mutable lua_standalone : bool;
|
|
|
mutable lua_vanilla : bool;
|
|
|
mutable lua_ver : float;
|
|
|
}
|
|
@@ -445,7 +446,7 @@ and gen_call ctx e el =
|
|
|
if List.length(fields) > 0 then incr count;
|
|
|
| { eexpr = TConst(TNull)} -> ()
|
|
|
| _ ->
|
|
|
- typing_error "__lua_table__ only accepts array or anonymous object arguments" e.epos;
|
|
|
+ typing_error "__lua_table__ only accepts array or anonymous object arguments" e.epos;
|
|
|
)) el;
|
|
|
spr ctx "})";
|
|
|
| TIdent "__lua__", [{ eexpr = TConst (TString code) }] ->
|
|
@@ -1876,6 +1877,7 @@ let alloc_ctx com =
|
|
|
separator = false;
|
|
|
found_expose = false;
|
|
|
lua_jit = Common.defined com Define.LuaJit;
|
|
|
+ lua_standalone = Common.defined com Define.LuaStandalone;
|
|
|
lua_vanilla = Common.defined com Define.LuaVanilla;
|
|
|
lua_ver = try
|
|
|
float_of_string (Common.defined_value com Define.LuaVer)
|
|
@@ -2139,25 +2141,35 @@ let generate com =
|
|
|
print_file (Common.find_file com "lua/_lua/_hx_dyn_add.lua");
|
|
|
end;
|
|
|
|
|
|
+ if ctx.lua_standalone && Option.is_some com.main then begin
|
|
|
+ print_file (Common.find_file com "lua/_lua/_hx_handle_error.lua");
|
|
|
+ end;
|
|
|
+
|
|
|
println ctx "_hx_static_init();";
|
|
|
|
|
|
List.iter (generate_enumMeta_fields ctx) com.types;
|
|
|
|
|
|
Option.may (fun e ->
|
|
|
- spr ctx "_G.xpcall(";
|
|
|
- let luv_run =
|
|
|
- (* Runs libuv loop if needed *)
|
|
|
- mk_lua_code ctx.com.basic "_hx_luv.run()" [] ctx.com.basic.tvoid Globals.null_pos
|
|
|
- in
|
|
|
- let fn =
|
|
|
- {
|
|
|
- tf_args = [];
|
|
|
- tf_type = com.basic.tvoid;
|
|
|
- tf_expr = mk (TBlock [e;luv_run]) com.basic.tvoid e.epos;
|
|
|
- }
|
|
|
- in
|
|
|
- gen_value ctx { e with eexpr = TFunction fn; etype = TFun ([],com.basic.tvoid) };
|
|
|
- spr ctx ", _hx_error)";
|
|
|
+ let luv_run =
|
|
|
+ (* Runs libuv loop if needed *)
|
|
|
+ mk_lua_code ctx.com.basic "_hx_luv.run()" [] ctx.com.basic.tvoid Globals.null_pos
|
|
|
+ in
|
|
|
+ if ctx.lua_standalone then begin
|
|
|
+ spr ctx "_G.xpcall(";
|
|
|
+ let fn =
|
|
|
+ {
|
|
|
+ tf_args = [];
|
|
|
+ tf_type = com.basic.tvoid;
|
|
|
+ tf_expr = mk (TBlock [e;luv_run]) com.basic.tvoid e.epos;
|
|
|
+ }
|
|
|
+ in
|
|
|
+ gen_value ctx { e with eexpr = TFunction fn; etype = TFun ([],com.basic.tvoid) };
|
|
|
+ spr ctx ", _hx_handle_error)";
|
|
|
+ end else begin
|
|
|
+ gen_expr ctx e;
|
|
|
+ newline ctx;
|
|
|
+ gen_expr ctx luv_run;
|
|
|
+ end;
|
|
|
newline ctx
|
|
|
) com.main;
|
|
|
|
|
@@ -2167,4 +2179,3 @@ let generate com =
|
|
|
let ch = open_out_bin com.file in
|
|
|
output_string ch (Buffer.contents ctx.buf);
|
|
|
close_out ch
|
|
|
-
|