Created
May 15, 2017 09:51
-
-
Save ibilon/e1f2e530449e2a52f24fb70a343fc47f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import haxe.macro.Context; | |
#if !macro | |
@:genericBuild(GenericClass.build()) | |
#end | |
class GenericClass<@:const Content> { | |
public static function build () { | |
return switch (Context.getLocalType()) | |
{ | |
case TInst(_, [TInst(_.get() => { kind: KExpr(macro $v{(s:String)}) }, _)]): | |
var c = macro class TestImpl { | |
public function new () { | |
} | |
public function execute () { | |
trace($v{s}); | |
} | |
}; | |
Context.defineType(c); | |
return Context.getType("TestImpl"); | |
default: | |
Context.error("Class expected", Context.currentPos()); | |
null; | |
} | |
} | |
} |
This file contains hidden or 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
//@:eager | |
typedef Sub = GenericClass<"test string from generic build">; | |
class Test { | |
public static function main () { | |
new Sub().execute(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment