Sorry for flooding forum these days but I have another question about constant arguments for macro functions and haven’t found any solution anywhere.
Is there a way to use a constant for a macro function argument that is an identifier but inlined and final without doing extra switch ?
Something like that doesn’t work:
static inline final s = "foo";
...
myMacroFunction( s );
...
macro public static function myMacroFunction( str : String ){...}
Update: Yes! There is a built-in way to support this, converting to a typed expression seems to inline variables, which is nice. You can then convert back to regular Expr so you can use ExprTools.getValue
/**
Return a value for an expression passed into a macro, even if that expression references other variables (so long as those variables are declared with inline)
**/
function evalConstExpr(x: Expr) {
return try {
ExprTools.getValue(Context.getTypedExpr(Context.typeExpr(x)));
} catch (e) {
Context.error("Must be a constant expression (i.e. and expression containing only constants or variables declared with `inline`", x.pos);
}
}