[英]CFor in Haxe using Macros
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. 我试图在Haxe中创建一个宏,它允许我编写传统的(C ++,Java)for循环并具有相同的功能。 But I am quite a beginner in Haxe...
但我是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 : 问题 :
What about this? 那这个呢?
https://gist.github.com/dpeek/7476625 https://gist.github.com/dpeek/7476625
The approach is different (applied to the context) but I think it is a little closer to the desired outcome. 方法不同(适用于上下文),但我认为它更接近预期的结果。
I don't see any potential target specific issues with your code. 我没有看到您的代码存在任何潜在的目标特定问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.