Skip to content

Instantly share code, notes, and snippets.

@dogles
Created November 17, 2014 15:49
Show Gist options
  • Save dogles/8172a8dca827f4296951 to your computer and use it in GitHub Desktop.
Save dogles/8172a8dca827f4296951 to your computer and use it in GitHub Desktop.
Unity Ifdefs
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