Skip to content

Instantly share code, notes, and snippets.

@back2dos
Last active December 31, 2015 22:59
Show Gist options
  • Select an option

  • Save back2dos/8057587 to your computer and use it in GitHub Desktop.

Select an option

Save back2dos/8057587 to your computer and use it in GitHub Desktop.
Stringly fail.
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());
}
}
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