Skip to content

Instantly share code, notes, and snippets.

@ibilon
Created May 15, 2017 09:51
Show Gist options
  • Save ibilon/e1f2e530449e2a52f24fb70a343fc47f to your computer and use it in GitHub Desktop.
Save ibilon/e1f2e530449e2a52f24fb70a343fc47f to your computer and use it in GitHub Desktop.
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;
}
}
}
//@: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