编写长/多行宏
Writing long / multiline macro
我正在写一些宏,这是示例代码
macro public static function test(object:Expr,name:Expr):Expr{
#if debug
return macro if ($object.get($name) == true) {$object.scan();$object.submit();return;};
#else
return macro trace("debug mode only");
#end
}
随着我的宏变得越来越长和复杂,我想除了用分号连接语句之外,必须有另一种方法来编写多行宏。
关于编写多行(生成的大约 50-100 行)宏有什么建议吗?
来自 this example, I found out that you can return a block of expression, not just one line. Simply add the statement inside a curly bracket and return it. You can also return a class 使用宏。
macro public static function test(object:Expr, name:Expr):Expr {
#if debug
return macro
if ($object.get($name) == true) {
$object.scan();
$object.submit();
return;
}
#else
return macro {
trace("not working!")
trace("compile with -Ddebug");
}
#end
}
我正在写一些宏,这是示例代码
macro public static function test(object:Expr,name:Expr):Expr{
#if debug
return macro if ($object.get($name) == true) {$object.scan();$object.submit();return;};
#else
return macro trace("debug mode only");
#end
}
随着我的宏变得越来越长和复杂,我想除了用分号连接语句之外,必须有另一种方法来编写多行宏。
关于编写多行(生成的大约 50-100 行)宏有什么建议吗?
来自 this example, I found out that you can return a block of expression, not just one line. Simply add the statement inside a curly bracket and return it. You can also return a class 使用宏。
macro public static function test(object:Expr, name:Expr):Expr {
#if debug
return macro
if ($object.get($name) == true) {
$object.scan();
$object.submit();
return;
}
#else
return macro {
trace("not working!")
trace("compile with -Ddebug");
}
#end
}