Advertisement
YellowAfterlife

String array access in typedef (Haxe)

Oct 12th, 2013
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 0.50 KB | None | 0 0
  1. package ;
  2.  
  3. abstract StringKey({}) from {} {
  4.     @:extern @:arrayAccess public inline function arrayAccess(key:String):Dynamic {
  5.         return Reflect.field(this, key);
  6.     }
  7.     @:extern @:arrayAccess public inline function arrayWrite<T>(key:String, value:T):T {
  8.         Reflect.setField(this, key, value);
  9.         return value;
  10.     }
  11. }
  12.  
  13. typedef Some = {
  14.     sk: StringKey,
  15. }
  16.  
  17. class Main {
  18.    
  19.     static function main() {
  20.         var a:Some = {
  21.             sk: {
  22.                 a: 4,
  23.                 b: 3
  24.             }
  25.         }
  26.         trace(a);
  27.         trace(a.sk["a"]);
  28.     }
  29.    
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement