Last active
August 29, 2015 14:03
-
-
Save postite/bea6649632107a100847 to your computer and use it in GitHub Desktop.
macro trace var name
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
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