Skip to content

Instantly share code, notes, and snippets.

@bendmorris
Created March 2, 2018 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendmorris/7695f36dbc8c2968c2a5d6bdde5f0592 to your computer and use it in GitHub Desktop.
Save bendmorris/7695f36dbc8c2968c2a5d6bdde5f0592 to your computer and use it in GitHub Desktop.
Haxe assert macro
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