|
@@ -462,22 +462,13 @@ let rec gen_call ctx e el in_value =
|
|
|
| TField (e, ((FInstance _ | FAnon _ | FDynamic _) as ef)), el ->
|
|
|
let s = (field_name ef) in
|
|
|
if Hashtbl.mem kwds s || not (valid_lua_ident s) then begin
|
|
|
- match e.eexpr with
|
|
|
- |TNew _-> (
|
|
|
- add_feature ctx "use._hx_apply_self";
|
|
|
- spr ctx "_hx_apply_self(";
|
|
|
- gen_value ctx e;
|
|
|
- print ctx ",\"%s\"" (field_name ef);
|
|
|
- if List.length(el) > 0 then spr ctx ",";
|
|
|
- concat ctx "," (gen_value ctx) el;
|
|
|
- spr ctx ")";
|
|
|
- );
|
|
|
- |_ -> (
|
|
|
- gen_value ctx e;
|
|
|
- print ctx "%s(" (anon_field s);
|
|
|
- concat ctx "," (gen_value ctx) (e::el);
|
|
|
- spr ctx ")"
|
|
|
- )
|
|
|
+ add_feature ctx "use._hx_apply_self";
|
|
|
+ spr ctx "_hx_apply_self(";
|
|
|
+ gen_value ctx e;
|
|
|
+ print ctx ",\"%s\"" (field_name ef);
|
|
|
+ if List.length(el) > 0 then spr ctx ",";
|
|
|
+ concat ctx "," (gen_value ctx) el;
|
|
|
+ spr ctx ")";
|
|
|
end else begin
|
|
|
gen_value ctx e;
|
|
|
print ctx ":%s(" (field_name ef);
|
|
@@ -840,7 +831,7 @@ and gen_expr ?(local=true) ctx e = begin
|
|
|
spr ctx "_hx_o({__fields__={";
|
|
|
concat ctx "," (fun (f,e) -> print ctx "%s=" (anon_field f); spr ctx "true") fields;
|
|
|
spr ctx "},";
|
|
|
- concat ctx "," (fun (f,e) -> print ctx "%s=" (anon_field f); gen_value ctx e) fields;
|
|
|
+ concat ctx "," (fun (f,e) -> print ctx "%s=" (anon_field f); gen_anon_value ctx e) fields;
|
|
|
spr ctx "})";
|
|
|
ctx.separator <- true
|
|
|
| TFor (v,it,e) ->
|
|
@@ -1024,6 +1015,35 @@ and gen_block_element ctx e =
|
|
|
semicolon ctx;
|
|
|
end;
|
|
|
|
|
|
+(* values generated in anon structures can get modified. Functions are bind-ed *)
|
|
|
+(* and include a dummy "self" leading variable so they can be called like normal *)
|
|
|
+(* instance methods *)
|
|
|
+and gen_anon_value ctx e =
|
|
|
+ match e with
|
|
|
+ | { eexpr = TFunction f} ->
|
|
|
+ let old = ctx.in_value, ctx.in_loop in
|
|
|
+ ctx.in_value <- None;
|
|
|
+ ctx.in_loop <- false;
|
|
|
+ print ctx "function(%s) " (String.concat "," ("self" :: (List.map ident (List.map arg_name f.tf_args))));
|
|
|
+ let fblock = fun_block ctx f e.epos in
|
|
|
+ (match fblock.eexpr with
|
|
|
+ | TBlock el ->
|
|
|
+ let bend = open_block ctx in
|
|
|
+ List.iter (gen_block_element ctx) el;
|
|
|
+ bend();
|
|
|
+ newline ctx;
|
|
|
+ |_ -> ());
|
|
|
+ spr ctx "end";
|
|
|
+ ctx.in_value <- fst old;
|
|
|
+ ctx.in_loop <- snd old;
|
|
|
+ ctx.separator <- true
|
|
|
+ | { etype = TFun (args, ret)} ->
|
|
|
+ spr ctx "function(_,...) return ";
|
|
|
+ gen_value ctx e;
|
|
|
+ spr ctx "(...) end";
|
|
|
+ | _->
|
|
|
+ gen_value ctx e
|
|
|
+
|
|
|
and gen_value ctx e =
|
|
|
let assign e =
|
|
|
mk (TBinop (Ast.OpAssign,
|
|
@@ -2092,7 +2112,6 @@ let generate com =
|
|
|
println ctx "end;";
|
|
|
end;
|
|
|
|
|
|
-
|
|
|
List.iter (generate_enumMeta_fields ctx) com.types;
|
|
|
|
|
|
(match com.main with
|