File tree Expand file tree Collapse file tree
src/rluacompiler/subcompilers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,9 +62,18 @@ class Classes extends SubCompiler
6262 if (properties .length > 0 )
6363 output + = ' ${classType .name }.__properties__ = { ${properties .join (" , " )}} \n ' ;
6464
65+ var inlinesStatics : Array <ClassVarData > = [];
6566 for (varf in varFields )
6667 {
67- if (varf .isStatic )
68+ if (! varf .isStatic )
69+ continue ;
70+ var expr = varf .field .expr ();
71+ if (expr == null )
72+ continue ;
73+
74+ if (expr .expr .match (TBlock (_ )))
75+ inlinesStatics .push (varf );
76+ else
6877 output + = main .fieldsSubCompiler .compileStaticImpl (varf );
6978 }
7079
@@ -81,6 +90,18 @@ class Classes extends SubCompiler
8190 if (r != null )
8291 output + = r ;
8392 }
93+
94+ if (inlinesStatics .length > 0 )
95+ {
96+ output + = " \n do\n " ;
97+ for (varf in inlinesStatics )
98+ {
99+ var r = main .expressionsSubCompiler .compileExpressionImpl (varf .field .expr (), 0 );
100+ if (r != null )
101+ output + = ' \t ' + StringTools .replace (r , " \n " , " \n\t " ) + ' \n ' ;
102+ }
103+ output + = ' end\n ' ;
104+ }
84105 }
85106
86107 return output ;
Original file line number Diff line number Diff line change @@ -319,9 +319,9 @@ class Expressions extends SubCompiler
319319 });
320320 var body = exprImpl (tfunc .expr , 1 );
321321
322- buff + = ' function( ${args .join (" , " )}) ${buff .enter }' ;
322+ buff + = ' ( function( ${args .join (" , " )}) ${buff .enter }' ;
323323 buff + = body ;
324- buff + = ' ${buff .leave }end' ;
324+ buff + = ' ${buff .leave }end) ' ;
325325 buff ;
326326
327327 case TVar (v , expr ):
Original file line number Diff line number Diff line change @@ -27,9 +27,18 @@ class Fields extends SubCompiler
2727
2828 public function compileStaticImpl (varf : ClassVarData ): Null <String >
2929 {
30- var output = ' ${varf .classType .name }. ${varf .field .name }' ;
31- if (varf .field .expr () != null )
32- output + = ' = ${main .expressionsSubCompiler .compileExpressionImpl (varf .field .expr (), 0 )}' ;
30+ var output = " " ;
31+ var expr = varf .field .expr ();
32+ if (expr != null )
33+ output + = main .expressionsSubCompiler .compileExpressionImpl (cast {
34+ expr : TBinop (OpAssign , {
35+ expr : TIdent (' ${varf .classType .name }. ${varf .field .name }' ),
36+ t : expr .t ,
37+ pos : expr .pos
38+ }, expr ),
39+ t : expr .t ,
40+ pos : expr .pos
41+ }, 0 );
3342 return output + " \n " ;
3443 }
3544
You can’t perform that action at this time.
0 commit comments