Advertisement
Masadow

APIBuilder

Mar 13th, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.09 KB | None | 0 0
  1. package beluga.core.api;
  2.  
  3. import haxe.macro.Expr.Field;
  4. import haxe.macro.Context;
  5. import haxe.macro.Expr;
  6. import beluga.core.MacroHelper;
  7. import haxe.macro.Compiler;
  8.  
  9. /**
  10.  * ...
  11.  * @author Masadow
  12.  */
  13. class APIBuilder
  14. {
  15.     macro public static function build() : Array<Field>
  16.     {
  17.         var fields : Array<Field> = Context.getBuildFields();
  18.         var pos = Context.currentPos();
  19.  
  20.         var modules : Array<String> = MacroHelper.getModules();
  21.         for (module in modules)
  22.         {
  23.             var api : String = "beluga.module." + module.toLowerCase() + ".api." + module.charAt(0).toUpperCase() + module.substr(1) + "Api";
  24.             fields.push({
  25.                 pos: pos,
  26.                 name: "do" + module.charAt(0).toUpperCase() + module.substr(1).toLowerCase(),
  27.                 meta: null,
  28.                 kind: FFun( {
  29.                     ret: null,
  30.                     params: [],
  31.                     expr: macro {
  32.                         d.dispatch(new $api(beluga, cast MacroHelper.getModuleInstanceByName($v{module})));
  33.                     },
  34.                     args: [ {
  35.                         value: null,
  36.                         type: macro : Dispatch,
  37.                         opt: false,
  38.                         name: "d"
  39.                     }]
  40.                 }),
  41.                 doc: null,
  42.                 access: [APublic]
  43.             });
  44.         }
  45.  
  46.         return fields;
  47.     }  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement