Haxe macro - Passing parameters to a macro -


i've got ne problem macro : passing parameter function...

i pass string function :

macro public static function gettags(?type : string) 

but there's compilation error (received expr , expected string). so, according documentation, did :

macro public static function gettags(?type : haxe.macro.expr.exprof<string>) {} 

that's cool, question following : how access string value ? that's not easy use.. in fact, if trace type have :

{ expr => econst(cident(type)), pos => #pos(lib/wx/core/container/servicecontainer.hx:87: characters 36-40) } 

i think have switch on type.expr, const contains variable name, not value.. how can access value ? , there easier way value (without switch example).

i think because call function not in macro, , think thing want not possible, prefer ask :)

thank you

as have mentioned, use variable capture in pattern matching:

class test {     macro public static function gettags(?type : haxe.macro.expr.exprof<string>) {         var str = switch(type.expr) {             case econst(cstring(str)):                 str;             default:                 throw "type should string const";         }         trace(str);         return type;     }     static function main() {         gettags("abc"); //test.hx:10: abc          var v = "abc";         gettags(v); //test.hx:7: characters 13-18 : type should string const     } } 

notice shown above, macro function can extract string value if input expression literal string. remember macro function run in compile-time, not know variable's run-time value.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -