Revisions
-
devboy revised this gist
Dec 20, 2011 . 2 changed files with 35 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,11 +13,23 @@ class ComponentMacro public static function build(): Array<Field> { var pos = haxe.macro.Context.currentPos(); var mk = function( expr ) return {expr: expr, pos: pos}; var fields = haxe.macro.Context.getBuildFields(); var tint = TPath({ pack : [], name : "Int", params : [], sub : null }); fields.push( { name : "ID", doc : null, meta : [], access : [AStatic, APublic], kind : FVar(tint, {expr: EConst(CInt(Std.string(idCount))), pos: pos}) , pos: pos }); fields.push( { name: "id", doc: null, meta:[], access: [APublic], kind: FFun( { ret: tint, params: [], args: [], expr: mk( EReturn( mk( EConst(CInt(Std.string(idCount)))))) } ), pos: pos } ); idCount++; return fields; } } 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 charactersOriginal file line number Diff line number Diff line change @@ -9,16 +9,33 @@ class Main { public static function main() { Lib.println( ComponentA.ID ); //0 Lib.println( new ComponentA().id() ); //0 Lib.println( new ComponentA().id() ); //0 Lib.println( ComponentB.ID ); //1 Lib.println( new ComponentB().id() ); //1 Lib.println( new ComponentB().id() ); //1 } } @:autoBuild( org.devboy.hxTask.ComponentMacro.build() ) interface Component { function id():Int; } class ComponentA implements Component { public function new() { } } class ComponentB implements Component { public function new() { } } -
devboy created this gist
Dec 20, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ 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; } } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ 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 { }