jan_flanders

Untitled

Aug 2nd, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class MacroTools
  2. {
  3.     // returns an array declaration of length len, filled with values 'val'
  4.     @:macro static public function array(len:Int, val:haxe.macro.Expr)
  5.     {
  6.         var arr = [];
  7.         for (i in 0...len)
  8.             arr.push(val);
  9.         return macro $[arr];
  10.     }
  11. }
  12. //--------------------------------------
  13. //usage :
  14. var arr = MacroTools.array(3,-1);
  15. // will be compiled as :
  16. var arr = [-1,-1,-1];
Advertisement
Add Comment
Please, Sign In to add comment