Created
March 2, 2018 17:47
-
-
Save bendmorris/7695f36dbc8c2968c2a5d6bdde5f0592 to your computer and use it in GitHub Desktop.
Haxe assert macro
This file contains 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
import haxe.macro.Context; | |
import haxe.macro.Expr; | |
import haxe.macro.ExprTools; | |
class AssertTest { | |
macro public static function assert(e:ExprOf<Bool>) { | |
#if debug | |
var assertion = ExprTools.toString(e); | |
return macro { | |
if (!$e) { | |
throw "Assertion failed: " + $v{assertion}; | |
} | |
}; | |
#else | |
return macro {}; | |
#end | |
} | |
static function main() { | |
assert(1 == 2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment