So, I love macros (yell at me).
I was trying to create a macro in Haxe, which allows me to write the traditional (C++, Java) for-loop and have the same functionality. But I am quite a beginner in Haxe...
Code:
import haxe.macro.Expr;
class Cfor {
macro public static function cfor(init: Expr, cond: Expr, post: Expr, body: Expr) {
return macro {
$init;
while ($cond) {
$body;
$post;
}
}
}
public static function main() {
trace("Traced");
cfor(var i = 0, i < 100, i++, {
var x = i * 2;
trace(x);
});
}
}
Questions:
- It already works (that specific test), but it's not that close to the traditional for-loop. How to improve that?
- Do you have any other improvements (style/functionality) for this code?
- Is there anything target specific which I should know of about this code?
- How can I see what this call to cfor expands to?