Created
November 17, 2014 15:49
-
-
Save dogles/8172a8dca827f4296951 to your computer and use it in GitHub Desktop.
Unity Ifdefs
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
package hugs; | |
import haxe.macro.Expr; | |
import haxe.macro.Context; | |
/** Utility to generate C# preprocessor macros */ | |
class Preprocessor | |
{ | |
public macro static function IF(name:ExprOf<String>) : Expr { | |
var ns = switch(name.expr) { | |
case EConst(CString(s)): s; | |
default: Context.error('Expected string', name.pos); null; | |
}; | |
var n = {expr:EConst(CString('#if ${ns} //')), pos:name.pos}; | |
return macro untyped __cs__($n); | |
} | |
public macro static function ELIF(name:ExprOf<String>) : Expr { | |
var ns = switch(name.expr) { | |
case EConst(CString(s)): s; | |
default: Context.error('Expected string', name.pos); null; | |
}; | |
var n = {expr:EConst(CString('#elif ${ns} //')), pos:name.pos}; | |
return macro untyped __cs__($n); | |
} | |
public macro static function ELSE() : Expr { | |
return macro untyped __cs__("#else //"); | |
} | |
public macro static function ENDIF() : Expr { | |
return macro untyped __cs__("#endif //"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment