snake5

haxe version

Jul 31st, 2019
624
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import haxe.macro.Type;
  3. import haxe.macro.Expr;
  4. import haxe.macro.Context;
  5. import haxe.io.Bytes;
  6. import sys.io.File;
  7.  
  8. class Parser
  9. {
  10.     var data : haxe.io.Bytes;
  11.     var at : Int = 0;
  12.    
  13.     static public function expr2name(name : Expr) : String
  14.     {
  15.         return switch (name.expr)
  16.         {
  17.             case EConst(cdata): switch (cdata) { case CIdent(id): id; default: "<ERROR>"; }
  18.             default: "<ERROR>";
  19.         };
  20.     }
  21.     macro static public function READ(name : Expr, type : Expr, size : Int = 4) : Expr
  22.     {
  23.         var nameStr = expr2name(name);
  24.         var typeStr = expr2name(type);
  25.         switch (typeStr)
  26.         {
  27.         case "Int32":
  28.             return macro
  29.             {
  30.                 var $nameStr : Int = data.getInt32(at);
  31.                 at += 4;
  32.                 trace($v{nameStr + " = "} + $i{nameStr});
  33.             };
  34.         case "Str":
  35.             return macro
  36.             {
  37.                 var $nameStr : String = data.getString(at, $v{size});
  38.                 at += $v{size};
  39.                 trace($v{nameStr + " = "} + $i{nameStr});
  40.             };
  41.         default:
  42.             return macro {};
  43.         }
  44.     }
  45.    
  46.     function new()
  47.     {
  48.         data = sys.io.File.getBytes("loop.wav");
  49.         READ(magic, Str, 4);
  50.         READ(size, Int32);
  51.     }
  52.     static public function main():Void
  53.     {
  54.         var parser = new Parser();
  55.         trace("Hello World");
  56.     }
  57. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×