Hej my dear friends, long time I haven’t written anything in the forum ! …
For those who want to bleed from eyes, I have another thing to show, some stupid code playing with macros.
I have an old static extension called .ns()
that acts like kind of “null safety”.
I can wrtie something like that and it works fine at run-time (here it will trace substitute
because all the rest is null…) :
var o : Dynamic = {};
trace( ( o.foo.bar().sub:Dynamic ).ns( "substitute" ) );
I was using it for long time without any problem, but yesterday I wanted to try that, but it failed :
trace( ( [ for (i in 0...5) { o : i } ] [ 2 ].o:Dynamic).ns() );
So I made some modifications and came into that : Try Haxe !
Now it works great for that and I’ll stay with that until in the future I will have another needs.
BUT the problem is that when I made changes, I came into a strange issue when (on compile-time, macro context), Haxe tolds me that “`” is not a valid variable name, whearas this is not my var name but Haxe compiler one during the macro context… :
Because this code :
(o.foo.bar().sub : Dynamic)
Is transformed into that by Haxe :
(cast {
var `:Array<{ var o : StdTypes.Int; }> = [];
{
{
`.push({ o : 0 });
};
{
`.push({ o : 1 });
};
{
`.push({ o : 2 });
};
{
`.push({ o : 3 });
};
{
`.push({ o : 4 });
};
};
`;
}[2].o)
As you can see the var name that Haxe gave to the array is “`”…
So to prevent that, I “rename” this kind of variables into a iteration in the expression as you can see L42 in the Macro class…
I know that I’m playing with hell getting back a @:this this
typed expression into an untyped one, and It’s not the best thing to do, but anyway, is it normal that Haxe compiler give “`” as a name var please ?
Once more, thanks for all that take attention to my “adventures”
Best,