So, I love macros (yelling at me).
I tried to create a macro in Haxe, which allows me to write a traditional (C ++, Java) for-loop and have the same functionality. But I'm pretty new to 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 (this particular test), but it is not so close to the traditional for-loop. How to improve this?
- Do you have any other improvements (style / functionality) for this code?
- Are there any specific goals I should know about this code about?
- How can I find out why this cfor call extends?
source
share