Skip to content

Instantly share code, notes, and snippets.

@whacked
Forked from devboy/ComponentMacro.hx
Created October 14, 2013 20:40
Show Gist options
  • Save whacked/6981820 to your computer and use it in GitHub Desktop.
Save whacked/6981820 to your computer and use it in GitHub Desktop.
package org.devboy.hxTask;
import neko.Lib;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
class ComponentMacro
{
private static var idCount = 0;
@:macro
public static function build(): Array<Field>
{
var pos = haxe.macro.Context.currentPos();
var fields = haxe.macro.Context.getBuildFields();
Lib.println( fields );
var tint = TPath({ pack : [], name : "Int", params : [], sub : null });
fields.push( { name : "id", doc : null, meta : [], access : [APublic], kind : FVar(tint, null), pos : pos });
fields.push( { name : "ID", doc : null, meta : [], access : [AStatic], kind : FVar(tint, null), pos : pos });
return fields;
}
}
package org.devboy.hxTask;
import neko.Lib;
import haxe.macro.Expr;
import haxe.macro.Context;
import org.devboy.hxTask.ComponentMacro;
class Main
{
public static function main()
{
Lib.println( ComponentA.ID );
}
}
@:autoBuild( org.devboy.hxTask.ComponentMacro.build() )
interface Component
{
var id:Int;
}
class ComponentA implements Component
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment