Skip to content

Instantly share code, notes, and snippets.

@postite
Last active August 29, 2015 14:03
Show Gist options
  • Save postite/bea6649632107a100847 to your computer and use it in GitHub Desktop.
Save postite/bea6649632107a100847 to your computer and use it in GitHub Desktop.
macro trace var name
import haxe.macro.Context;
import haxe.macro.Expr;
import Test.Mac.getMyName;
class Test {
static var pup="3ze";
var plop:String;
static function main() {
new Test();
}
function new():Void
{
plop="plip";
var z="rt";
var p=[];
var obj=cast {};
obj.x=3;
var arr:Array<Dynamic>=[plop,z,p];
trace( getMyName(plop) );
trace(getMyName(z));
trace(getMyName(p));
trace(getMyName(obj) + " value is "+ obj);
trace( "after");
}
}
class Mac{
macro public static function getMyName(field:Expr){
var pos = Context.currentPos();
var t:String;
switch (field.expr)
{
case EConst(c):t=(c.getParameters()[0]);
default:throw "nope";
}
return macro '$t';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment