Last active
May 8, 2021 18:48
-
-
Save haxiomic/06c1007495f853129c384a39c99bfa28 to your computer and use it in GitHub Desktop.
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). Originally from this thread https://community.haxe.org/t/macro-constant-arg-inline-final/3007
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example