Main.hx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package test;
  2. import haxe.macro.Context;
  3. import haxe.macro.Expr;
  4. private class Bar {
  5. public function new() { }
  6. public function getValue() {
  7. return "foo";
  8. }
  9. }
  10. class Main
  11. {
  12. static function main()
  13. {
  14. defineFooExtendsBarInLocalModule();
  15. #if !macro
  16. var foo = new Foo();
  17. Sys.stderr().writeString(foo.getValue());
  18. #end
  19. }
  20. macro static function defineFooExtendsBarInLocalModule(?e)
  21. {
  22. var infos = Context.getPosInfos(Context.currentPos());
  23. var position = Context.makePosition({min:0, max:0, file:infos.file});
  24. var superTypePath:TypePath =
  25. {
  26. pack: [],
  27. name: "Bar",
  28. sub: null
  29. }
  30. var kind:TypeDefKind = TypeDefKind.TDClass(superTypePath);
  31. var Foo:TypeDefinition =
  32. {
  33. name: "Foo",
  34. pack: ["test"],
  35. pos: position,
  36. kind: kind,
  37. fields: []
  38. }
  39. Context.defineModule(Context.getLocalModule(), [Foo]);
  40. return e;
  41. }
  42. }