Created
          May 7, 2014 10:07 
        
      - 
      
 - 
        
Save postite/07f43ed4fda395ef22ec to your computer and use it in GitHub Desktop.  
    macro function to format cocoascript like methods
  
        
  
    
      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
    
  
  
    
  | public static function cocoize() | |
| { | |
| trace( "cocoize"); | |
| var fields = Context.getBuildFields(); | |
| //parsing fields | |
| for ( f in fields){ | |
| //parsing metas | |
| for ( m in f.meta){ | |
| //meta name | |
| switch (m.name){ | |
| case ":cocoize": | |
| //kind of expression | |
| switch (f.kind) { | |
| case FVar(t,_): | |
| trace("it's a var" +t); | |
| case FFun(t): | |
| trace( "its an expr"+t); | |
| //trace( f.kind.getParameters()[0].args); | |
| var args:Array<Dynamic>=f.kind.getParameters()[0].args; | |
| trace( "args="+args); | |
| switch (args.length){ | |
| case 0:trace("no params" ); | |
| case 1:trace("one param"); | |
| default: | |
| var pos = f.pos; | |
| var neo:haxe.macro.Field=cast {} | |
| neo.name=f.name; | |
| var neoArgs=[]; | |
| var argz=""; | |
| for ( arg in args){ | |
| argz+=arg.name+","; | |
| neo.name+="_"+arg.name; | |
| neoArgs.push({name:arg.name, type:arg.type, opt : false, value : null}); | |
| } | |
| var p= argz.substr(0,-1); | |
| trace( "p="+p); | |
| var set = { | |
| args : neoArgs, | |
| params : null, | |
| ret:f.kind.getParameters()[0].ret, | |
| expr : Context.parse(" untyped this."+neo.name+"("+ p +")",pos), | |
| }; | |
| // | |
| trace("one more time"); | |
| //f.name=neo.name; | |
| neo.access=[APublic,AInline]; | |
| neo.kind=FFun( set); | |
| neo.meta=[]; | |
| neo.pos= pos; | |
| //neo.kind=f.kind; | |
| f.access= neo.access; | |
| f.kind=neo.kind; | |
| //fields.push(neo); | |
| } | |
| default: | |
| trace("i really don't know"); | |
| } | |
| case _: trace( "not the good meta"+ m.name); | |
| } | |
| } | |
| } | |
| return fields; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment