Haxe Forum > how to convert a expr to string
-
joydance Jul 30 at 05:38
Hello guys, I am recently insterested of haxe macro, and think it's very useful.
And now I have a question: it's able to convert a expression to a string in a macro definition, because I want write something like this:MyMacro.println(obj.a, obj.b, obj.c) //and it will output this :
Lib.println("obj.a:" + obj.a)
Lib.println("obj.b:" + obj.b)I just not understand how to convert a expr like obj.a to a string as "obj.a", is there any way to do this?
Thanks a lot.:) -
Rodin Jul 31 at 09:26
I don't know about converting
obj.a
into the string "obj.a", but you could useReflect.fields(obj)
to get all the fields and then use Lambda mapUsing Lambda; var debug = Reflect.fields(obj).map(function(field:String) : String { return "obj." + field + ": " + Reflect.field(obj,field); }).array().join("\n");
to get a nice string for all the field of an object without having to specify them one by one.Hope this helps
< Prev
| Page 1 / 1 |
Next >