compilation - Is there a mechanism for C++ like macros in haxe? -
in c++ have macros like:
class="lang-cpp prettyprint-override">#ifdef debug #define dbgassert(condition, message)/ if(!(condition)){ implementation.assert(message); } #else #define dbgassert(condition, message) #endif
this approach efficient status never tested if we're not in debug mode particularly when of conditions can particularly heavy on cpu.
is there way implement type of 1 liners in haxe?
this simple illustration there macros dozen conditional definitions (depending on multiple parameters) can't efficiently maintain redundant redefinitions on place.
here more interesting scheme allows me test simplest status , add together heavyer tests depending on level:
class="lang-cpp prettyprint-override">#if 4 == assert4level #define lvlassert4(conditionlvl1, conditionlvl2, conditionlvl3, conditionlvl4, message)/ myassert((conditionlvl1) && (conditionlvl2) && (conditionlvl3) && (conditionlvl4), message) #elif 3 == assert4level #define lvlassert4(conditionlvl1, conditionlvl2, conditionlvl3, conditionlvl4, message)/ myassert((conditionlvl1) && (conditionlvl2) && (conditionlvl3), message) #elif 2 == assert4level #define lvlassert4(conditionlvl1, conditionlvl2, conditionlvl3, conditionlvl4, message)/ myassert((conditionlvl1) && (conditionlvl2), message) #else #define lvlassert4(conditionlvl1, conditionlvl2, conditionlvl3, conditionlvl4, message)/ myassert((conditionlvl1), message) #endif
how can replicate behavior without executing conditions?
frabbits reply right 1 situation, here macro version well.
@:macro static public function dbgassert(condition, message) { #if debug homecoming macro if (!($condition)) { implementation.assert($message); } #else homecoming macro {}; #end }
macros compilation haxe conditional-compilation
No comments:
Post a Comment