MacroHelper.hx 812 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package h3d.impl;
  2. import haxe.macro.Context;
  3. import haxe.macro.Expr;
  4. class MacroHelper {
  5. #if macro
  6. static function replaceGLLoop( e : Expr ) {
  7. switch( e.expr ) {
  8. case EConst(CIdent("gl")):
  9. e.expr = EConst(CIdent("GL"));
  10. default:
  11. haxe.macro.ExprTools.iter(e, replaceGLLoop);
  12. }
  13. }
  14. public static function replaceGL() {
  15. var fields = Context.getBuildFields();
  16. for( f in fields )
  17. switch( f.kind ) {
  18. case FFun(f):
  19. if( f.expr != null ) replaceGLLoop(f.expr);
  20. case FVar(_,e):
  21. if( e != null ) replaceGLLoop(e);
  22. default:
  23. }
  24. return fields;
  25. }
  26. #end
  27. public static macro function getResourcesPath() {
  28. var dir = haxe.macro.Context.definedValue("resourcesPath");
  29. if( dir == null ) dir = "res";
  30. return macro $v{try Context.resolvePath(dir) catch( e : Dynamic ) null};
  31. }
  32. }