I would like to do the following:
macro
public static function de(debug:ExprOf<String>,e:Expr):Expr {
var debug_s:String=ExprTools.toString(debug);
debug_s=debug_s.substring(1,debug_s.length-1);
if(Context.defined(debug_s)) {
var es:String=ExprTools.toString(e);
var r:String="{"+es+"}"; //objective is to remove {} for instances of single line expressions and prune them in the instance of multiline passed expressions
return Context.parse(r,Context.currentPos());
}
return Context.parse("{}",Context.currentPos());
}
The above should function similar to the conditional compilation directive. However, it does not because in the instance of newly declared variables in the expressions, their scope is limited to the generated expression subblock.
Consider this:
T.de('render_performance_debug',{
var start:Float=Utils.time_precise();
});
render_function();
T.de('render_performance_debug',{
Utils.measure_trace("render",start); //start does not exist
});
There is value in using this type of conditional as opposed to conditional compilation because:
1. It can potentially facilitate enabling a debug variable at runtime.
2. It facilitates the full power of macros and general purpose computing constructs as opposed to the limited functionality provided by conditional compilation.