Advertisement
YellowAfterlife

Tables and Haxe

Dec 30th, 2013
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 0.47 KB | None | 0 0
  1. typedef MyTable = {
  2.     x: Int,
  3.     t: String
  4. };
  5.  
  6. class Main {
  7.     static function main() {
  8.         var m:MyTable = {
  9.             x: 10,
  10.             t: "string"
  11.         };
  12.         trace(m.t); // gets you intellisense
  13.        
  14.         var n:Dynamic = {
  15.             x: 10,
  16.             t: "string"
  17.         };
  18.         trace(n.t); // doesn't get you any (ala Lua)
  19.        
  20.         // make a copy of table:
  21.         var n2:Dynamic = { };
  22.         for (f in Reflect.fields(n)) Reflect.setField(n2, f, Reflect.field(n, f));
  23.         n2.t = "other";
  24.         trace(n2.t + ", " + n.t);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement