Browse Source

Lua: Workaround for invoking instance methods on constants

In Haxe, you can invoke a method directly on an anonymous value type,
such as "foo bar".charAt(0).  However, in Lua, this isn't possible.
Once again, I'm wrapping the expression in an iife.

I've been using iife's a lot to work around missing features of ua.
This is somewhat problematic because closures like this are slow in Lua.
in this case it might be a better idea to try and inline the basic
String functions.  That caused some problems with some of the tests, but
there may still be a way forward there.
Justin Donaldson 10 years ago
parent
commit
a7f4ca4139
1 changed files with 9 additions and 0 deletions
  1. 9 0
      genlua.ml

+ 9 - 0
genlua.ml

@@ -355,6 +355,15 @@ let rec gen_call ctx e el in_value =
 		print ctx ":%s(" (field_name ef);
 		concat ctx "," (gen_value ctx) el;
 		spr ctx ")";
+	| TField ( { eexpr = TConst(TInt _ | TFloat _| TString _| TBool _) } as e , ((FInstance _ | FAnon _) as ef)), el ->
+		spr ctx "(function(x) return x";
+		spr ctx ":";
+		print ctx "%s" (field_name ef);
+		spr ctx "(";
+		concat ctx "," (gen_value ctx) el;
+		spr ctx ") end )(";
+		gen_value ctx e;
+		spr ctx ")";
 	| TField (e, ((FInstance _ | FAnon _) as ef)), el ->
 		gen_value ctx e;
 		spr ctx ":";