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