Created
March 21, 2016 15:56
-
-
Save Simn/fbb670a0196b4bf42d97 to your computer and use it in GitHub Desktop.
Nicolas about Haxe #3
This file contains 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; | |
import haxe.macro.Expr; | |
class MyMacro { | |
public static function build( url : String ) { | |
var h = haxe.Http.requestUrl(url); | |
//trace(h); | |
var r = ~/id=["']([A-Za-z0-9]+)["']/; | |
var ids = []; | |
while ( r.match(h) ) { | |
var id = r.matched(1); | |
ids.remove(id); | |
ids.push(id); | |
h = r.matchedRight(); | |
} | |
var fields = Context.getBuildFields(); | |
var gtype = TAnonymous([for ( id in ids ) { name : id, pos : Context.currentPos(), kind : FVar(macro : String) }]); | |
var gids : Field = { | |
name : "gids", | |
pos : Context.currentPos(), | |
kind : FVar(gtype), | |
access : [AStatic], | |
}; | |
fields.push(gids); | |
return fields; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment