Advertisement
YellowAfterlife

Haxe ArrayAccess?

Nov 23rd, 2013
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 0.49 KB | None | 0 0
  1. class Main {
  2.     public var one:Int = 1;
  3.     public function new() {
  4.         var some = new Some(this);
  5.         trace(some[0]);
  6.         trace(some[1]);
  7.     }
  8.     public static function main() new Main();
  9. }
  10.  
  11. class Some implements ArrayAccess<Int> {
  12.     public var main:Main;
  13.     public function new(m:Main) { main = m; }
  14.     @:arrayAccess public function arrayAccess(k:Int):Int {
  15.         return k == 1 ? main.one : -1;
  16.     }
  17.     @:arrayAccess public function arrayWrite(k:Int, v:Int):Int {
  18.         return k == 1 ? main.one = v : v;
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement