Last active
December 31, 2015 22:59
-
-
Save back2dos/8057587 to your computer and use it in GitHub Desktop.
Stringly fail.
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
| package ; | |
| #if macro | |
| import haxe.macro.Expr; | |
| import haxe.macro.Context; | |
| using haxe.macro.ExprTools; | |
| #end | |
| class Foo { | |
| public function new() { | |
| } | |
| public inline function add(foo:Dynamic) { | |
| trace('add $foo'); | |
| return this; | |
| } | |
| macro public function transmogrify(ethis, exprs:Array<Expr>) { | |
| var r:String="{\n"; | |
| var first:Bool=true; | |
| for(v in exprs) { | |
| if(first) { | |
| first=false; | |
| } else { | |
| r+="\n"; | |
| } | |
| var vs:String = ExprTools.toString(v); | |
| r+=ExprTools.toString(ethis)+".add("+vs+");"; | |
| } | |
| r+="}"; | |
| return Context.parse(r,Context.currentPos()); | |
| } | |
| } |
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
| package ; | |
| class Run { | |
| static function main() { | |
| new Foo().add('foo').transmogrify('a', 'b', 'c'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment