Advertisement
Masadow

Macro trick

Mar 3rd, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 0.74 KB | None | 0 0
  1.     private static var _modulesArray : Array<String> = null;
  2.     public static var modulesArray(get, null) : Array<String>;
  3.  
  4.     public static function get_modulesArray() : Array<String>
  5.     {
  6.         if (_modulesArray == null)
  7.         {
  8.             _modulesArray = new Array<String>();
  9.             importConfig();
  10.         }
  11.         return _modulesArray;
  12.     }
  13.  
  14.     public static function fillArray()
  15.     {
  16.         _modulesArray.push("File 1");
  17.         Sys.println("Should be printed once");
  18.     }
  19.    
  20.     private static var cached : Expr = null;
  21.     macro public static function importConfig()
  22.     {
  23.         if (_modulesArray == null)
  24.             _modulesArray = new Array<String>();
  25.         if (cached != null)
  26.             return cached;
  27.         fillArray();
  28.         cached = Context.makeExpr("Awesome config", Context.currentPos());
  29.         return cached;
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement